厨师模板资源not_if solo

时间:2016-01-24 05:13:42

标签: chef chef-recipe chef-solo test-kitchen

我有以下厨师食谱,当它在厨师独奏下融合时,我不想运行模板资源。在运行厨房时,它似乎没有服从not_if。它仍然试图连接厨师服务器。请帮忙。

配方,

...
<% @nodes.each do |n| -%>
    <% if (n['fqdn'] && n['ipaddress']) -%>
        <%= n['ipaddress'] %> <%= n['fqdn']  %>
    <% end -%>
<% end -%>
...

模板,

---
driver:
  name: vagrant

provisioner:
  name: chef_solo

platforms:
  - name: centos-6.7
...

.kitchen.yml

  <!doctype html>
<html>
<head>
<title>SIGN IN</title>
<link type="text/css" rel="stylesheet" href="freshstyle.css">
</head>
<body>


<div id="header1">

</div>              

<div id="header2">   

</div>


<div class="content">
<div id="main">
<p>The December 1969 nor'easter was an intense winter storm that most notably impacted
 the Northeastern United States and southern Quebec on December 25–28.
 The multi-faceted storm system was blamed for at least 20 deaths in the United States
 and 15 in Canada. 
 After developing over Texas and spawning several damaging tornadoes in the Deep South, 
 the cyclone advanced to the Eastern Seaboard, dropping more than 1 ft (30 cm) of snow
 as far south as Washington, D.C. The nor'easter intensified and slowed as it moved into
 New England, delivering 40 inches (100 cm) of snowfall in some places, with heavy rain
 near the coast and a severe ice storm in Vermont and New Hampshire. In Canada, Montreal
 received 27.5 in (70 cm) of snow over a period of 60 hours. Equipment failures and 
 drifts up to 30 ft (9 m) left roadways blocked for many days throughout the affected 
 region, and some communities became inaccessible except by snowmobile. 
 The weight of the snow and ice, combined with gale-force winds, collapsed roofs and 
 brought down power lines. Ice jams and excessive rainfall created widespread flooding
 in eastern New England. (Full article...) </p>
</div>
<div class="sideryt">
<div id="login">
         <form action="" method="">
         <table cellpadding=2 cellspacing=5 >

         <tr>
         <td>
               <label for="fname"><b>Email</b></label> </td>
               <td><input type="text" id="fname" name=""/></td></tr>
                <tr><td>
               <label for="fname"><b>Password</b></label></td>
               <td><input type="text" id="fname" name=""/></td></tr>

               <tr><td colspan=2>
               <a class="button" href="">Login</a></td>          
               </tr>
               </table>
               </form>
               </div>

         <div class="create">
         <h1>Create an account</h1>
          <h2>register for free.Always!</h2></div>
         <div id="signup">
         <form action="" method="">
         <table cellpadding=2 cellspacing=5 >
         <tr><td colspan=2>
               <a class="button" href="file:///S:/mini%20project%20stuff/sign_up.html">Signup</a></td>          
               </tr>
               </table>
         </form>

</div>   
</div>
</div>

<div id="footer">
 <div id="foot">
  <ul>
<li><a href="">About Us</a></li>
<li><a href="">FAQS</a></li>
<li><a href="">contacts</a></li>
  </div>
copyright &copy shiv 2016
</div>


</body>

</html>

1 个答案:

答案 0 :(得分:2)

将正常值传递给not_if意味着它被解释为要运行的命令。您想要的是块形式:

not_if { Chef::Config[:solo] }

那就是说,问题并非如此。更深层次的问题是直接在资源体中的所有值都在编译时得到评估。您希望使用lazy帮助程序来延迟评估,以便仅在资源实际运行时才使用它们:

variables(lazy {
  {:nodes => search(:node, 'ipaddress:*')}
})