chef-sugar-ng 4.2.2 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/chef/sugar/init.rb +1 -2
 - data/lib/chef/sugar/version.rb +1 -1
 - data/lib/chef/sugar/virtualization.rb +1 -1
 - metadata +8 -68
 - data/.github/lock.yml +0 -3
 - data/.github/reaction.yml +0 -1
 - data/.gitignore +0 -26
 - data/.kitchen.yml +0 -16
 - data/.travis.yml +0 -17
 - data/CHANGELOG.md +0 -261
 - data/CONTRIBUTING.md +0 -20
 - data/Gemfile +0 -2
 - data/README.md +0 -540
 - data/Rakefile +0 -11
 - data/chef-sugar-ng.gemspec +0 -33
 - data/libraries/chef-sugar.rb +0 -1
 - data/metadata.rb +0 -24
 - data/recipes/default.rb +0 -20
 - data/spec/spec_helper.rb +0 -25
 - data/spec/support/shared_examples.rb +0 -20
 - data/spec/unit/chef/sugar/architecture_spec.rb +0 -129
 - data/spec/unit/chef/sugar/cloud_spec.rb +0 -149
 - data/spec/unit/chef/sugar/constraints_spec.rb +0 -45
 - data/spec/unit/chef/sugar/core_extensions/array_spec.rb +0 -10
 - data/spec/unit/chef/sugar/core_extensions/object_spec.rb +0 -62
 - data/spec/unit/chef/sugar/core_extensions/string_spec.rb +0 -48
 - data/spec/unit/chef/sugar/data_bag_spec.rb +0 -118
 - data/spec/unit/chef/sugar/docker_spec.rb +0 -39
 - data/spec/unit/chef/sugar/init_spec.rb +0 -74
 - data/spec/unit/chef/sugar/ip_spec.rb +0 -53
 - data/spec/unit/chef/sugar/kernel_spec.rb +0 -16
 - data/spec/unit/chef/sugar/kitchen_spec.rb +0 -18
 - data/spec/unit/chef/sugar/node_spec.rb +0 -172
 - data/spec/unit/chef/sugar/platform_family_spec.rb +0 -166
 - data/spec/unit/chef/sugar/platform_spec.rb +0 -342
 - data/spec/unit/chef/sugar/ruby_spec.rb +0 -39
 - data/spec/unit/chef/sugar/run_context_spec.rb +0 -19
 - data/spec/unit/chef/sugar/shell_spec.rb +0 -104
 - data/spec/unit/chef/sugar/vagrant_spec.rb +0 -37
 - data/spec/unit/chef/sugar/virtualization_spec.rb +0 -135
 - data/spec/unit/recipes/default_spec.rb +0 -9
 
    
        data/CONTRIBUTING.md
    DELETED
    
    | 
         @@ -1,20 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            Contributing to Chef Sugar
         
     | 
| 
       2 
     | 
    
         
            -
            ===============================
         
     | 
| 
       3 
     | 
    
         
            -
            The process for contributing to Chef sugar is rather straight-forward. It is unlikely that you'll need to modify the actual Chef recipe, so it's assumed that you want to work on the Gem itself.
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            1. Fork the repository on GitHub.
         
     | 
| 
       6 
     | 
    
         
            -
            2. Clone your fork.
         
     | 
| 
       7 
     | 
    
         
            -
            3. Create a new, semantically-named branch:
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                    $ git checkout -b my_feature_branch
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            4. Make any changes, ensuring you write adequate test coverage.
         
     | 
| 
       12 
     | 
    
         
            -
            5. Document your changes (YARD).
         
     | 
| 
       13 
     | 
    
         
            -
            6. Run the tests (make sure they pass).
         
     | 
| 
       14 
     | 
    
         
            -
            7. Submit a Pull Request on GitHub.
         
     | 
| 
       15 
     | 
    
         
            -
            8. (optional) Ping me on Twitter (@sethvargo)
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
            Additionally, please **DO NOT**:
         
     | 
| 
       18 
     | 
    
         
            -
            - Modify the version of the cookbook or gem.
         
     | 
| 
       19 
     | 
    
         
            -
            - Update the CHANGELOG
         
     | 
| 
       20 
     | 
    
         
            -
            - Make unnecessary changes to the gemspec
         
     | 
    
        data/Gemfile
    DELETED
    
    
    
        data/README.md
    DELETED
    
    | 
         @@ -1,540 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Chef Sugar
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            [][gem] [][travis]
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            Chef Sugar is a Gem & Chef Recipe that includes series of helpful syntactic sugars on top of the Chef core and other resources to make a cleaner, more lean recipe DSL, enforce DRY principles, and make writing Chef recipes an awesome and fun experience!
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            ## Requirements
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            ### Platforms
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            - any platform
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            ### Chef
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            - Chef 12.10+
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            ### Cookbooks
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
            - none
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
            ## Installation
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
            If you want to develop/hack on chef-sugar, please see the CONTRIBUTING.md.
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
            If you are using Berkshelf, add `chef-sugar` to your `Berksfile`:
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       29 
     | 
    
         
            -
            cookbook 'chef-sugar'
         
     | 
| 
       30 
     | 
    
         
            -
            ```
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
            Otherwise, you can use `knife` or download the tarball directly from the community site:
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       35 
     | 
    
         
            -
            knife cookbook site install chef-sugar
         
     | 
| 
       36 
     | 
    
         
            -
            ```
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
            ## Usage
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
            Simply depend on this cookbook in the metadata of your cookbook and the gem will be installed and required..
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
            Requiring the Chef Sugar Gem will automatically extend the Recipe DSL, `Chef::Resource`, and `Chef::Provider` with helpful convenience methods.
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
            ### Module Method
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
            If you are working outside of the Recipe DSL, you can use the module methods instead of the Recipe DSL. In general, the module methods have the same name as their Recipe-DSL counterparts, but require the node object as a parameter. For example:
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
            In a Recipe:
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       51 
     | 
    
         
            -
            # cookbook/recipes/default.rb
         
     | 
| 
       52 
     | 
    
         
            -
            do_something if windows?
         
     | 
| 
       53 
     | 
    
         
            -
            ```
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
            In a Library as a singleton:
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       58 
     | 
    
         
            -
            # cookbook/libraries/default.rb
         
     | 
| 
       59 
     | 
    
         
            -
            def only_on_windows(&block)
         
     | 
| 
       60 
     | 
    
         
            -
              yield if Chef::Sugar::PlatformFamily.windows?(@node)
         
     | 
| 
       61 
     | 
    
         
            -
            end
         
     | 
| 
       62 
     | 
    
         
            -
            ```
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
            In a Library as a Mixin:
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       67 
     | 
    
         
            -
            # cookbook/libraries/default.rb
         
     | 
| 
       68 
     | 
    
         
            -
            include Chef::Sugar::PlatformFamily
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
            def only_on_windows(&block)
         
     | 
| 
       71 
     | 
    
         
            -
              yield if windows?(@node)
         
     | 
| 
       72 
     | 
    
         
            -
            end
         
     | 
| 
       73 
     | 
    
         
            -
            ```
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
            ## API
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
            **Note:** For the most extensive API documentation, please see the YARD documentation.
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
            ### Architecture
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
            **Note:** Some of the architecture commands begin with an underscore (`_`) because Ruby does not permit methods to start with a numeric.
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
            - `_64_bit?`
         
     | 
| 
       84 
     | 
    
         
            -
            - `_32_bit?`
         
     | 
| 
       85 
     | 
    
         
            -
            - `intel?`
         
     | 
| 
       86 
     | 
    
         
            -
            - `sparc?`
         
     | 
| 
       87 
     | 
    
         
            -
            - `ppc64?`
         
     | 
| 
       88 
     | 
    
         
            -
            - `ppc64le?`
         
     | 
| 
       89 
     | 
    
         
            -
            - `powerpc?`
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       94 
     | 
    
         
            -
            execute 'build[my binary]' do
         
     | 
| 
       95 
     | 
    
         
            -
              command '...'
         
     | 
| 
       96 
     | 
    
         
            -
              not_if  { _64_bit? }
         
     | 
| 
       97 
     | 
    
         
            -
            end
         
     | 
| 
       98 
     | 
    
         
            -
            ```
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
            ### Cloud
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
            - `azure?`
         
     | 
| 
       103 
     | 
    
         
            -
            - `cloud?`
         
     | 
| 
       104 
     | 
    
         
            -
            - `digitalocean?`
         
     | 
| 
       105 
     | 
    
         
            -
            - `ec2?`
         
     | 
| 
       106 
     | 
    
         
            -
            - `eucalyptus?`
         
     | 
| 
       107 
     | 
    
         
            -
            - `gce?`
         
     | 
| 
       108 
     | 
    
         
            -
            - `linode?`
         
     | 
| 
       109 
     | 
    
         
            -
            - `openstack?`
         
     | 
| 
       110 
     | 
    
         
            -
            - `cloudstack?`
         
     | 
| 
       111 
     | 
    
         
            -
            - `rackspace?`
         
     | 
| 
       112 
     | 
    
         
            -
            - `softlayer?`
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       117 
     | 
    
         
            -
            template '/tmp/config' do
         
     | 
| 
       118 
     | 
    
         
            -
              variables(
         
     | 
| 
       119 
     | 
    
         
            -
                # See also: best_ip_for
         
     | 
| 
       120 
     | 
    
         
            -
                ipaddress: cloud? ? node['local_ipv4'] : node['public_ipv4']
         
     | 
| 
       121 
     | 
    
         
            -
              )
         
     | 
| 
       122 
     | 
    
         
            -
            end
         
     | 
| 
       123 
     | 
    
         
            -
            ```
         
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
            ### Core Extensions
         
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
            **Note:** Core extensions are **not** included by default. You must require the `chef/sugar/core_extensions` module manually to gain access to these APIs:
         
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       130 
     | 
    
         
            -
            require 'chef/sugar/core_extensions'
         
     | 
| 
       131 
     | 
    
         
            -
            ```
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
            - `String#satisfies?`
         
     | 
| 
       134 
     | 
    
         
            -
            - `String#satisfied_by?`
         
     | 
| 
       135 
     | 
    
         
            -
            - `Array#satisfied_by?`
         
     | 
| 
       136 
     | 
    
         
            -
            - `Object#blank?`
         
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       141 
     | 
    
         
            -
            # Checking version constraints
         
     | 
| 
       142 
     | 
    
         
            -
            '1.0.0'.satisfies?('~> 1.0') #=> true
         
     | 
| 
       143 
     | 
    
         
            -
            '~> 1.0'.satisfied_by?('1.0') #=> true
         
     | 
| 
       144 
     | 
    
         
            -
            ```
         
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       147 
     | 
    
         
            -
            # Check for an object's presence
         
     | 
| 
       148 
     | 
    
         
            -
            ''.blank? #=> true
         
     | 
| 
       149 
     | 
    
         
            -
            ['hello'].blank? #=> false
         
     | 
| 
       150 
     | 
    
         
            -
            ```
         
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
       152 
     | 
    
         
            -
            ### Data Bag
         
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
            - `encrypted_data_bag_item` - a handy DSL method for loading encrypted data bag items the same way you load a regular data bag item; this requires `Chef::Config[:encrypted_data_bag_secret]` is set!
         
     | 
| 
       155 
     | 
    
         
            -
            - `encrypted_data_bag_item_for_environment` - find the encrypted data bag entry for the current node's Chef environment.
         
     | 
| 
       156 
     | 
    
         
            -
            - `data_bag_item_for_environment` - find the data bag entry for the current node's Chef environment.
         
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       161 
     | 
    
         
            -
            encrypted_data_bag_item('accounts', 'hipchat')
         
     | 
| 
       162 
     | 
    
         
            -
            ```
         
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       165 
     | 
    
         
            -
            encrypted_data_bag_item_for_environment('accounts', 'github')
         
     | 
| 
       166 
     | 
    
         
            -
            ```
         
     | 
| 
       167 
     | 
    
         
            -
             
     | 
| 
       168 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       169 
     | 
    
         
            -
            data_bag_item_for_environment('accounts', 'github')
         
     | 
| 
       170 
     | 
    
         
            -
            ```
         
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
       172 
     | 
    
         
            -
            ### Docker
         
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
            Chef Sugar looks for hints to see if the node being converged is a Docker container. When [Ohai supports checking other nodes](https://github.com/opscode/ohai/pull/428), Chef Sugar will automatically pick up the information.
         
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
            - `docker?`
         
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
       180 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       181 
     | 
    
         
            -
            template '/runme' do
         
     | 
| 
       182 
     | 
    
         
            -
              only_if { docker?(node) }
         
     | 
| 
       183 
     | 
    
         
            -
            end
         
     | 
| 
       184 
     | 
    
         
            -
            ```
         
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
            ### Attributes
         
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
            Chef Sugar adds more Chef-like DSL to attribute definitions. Instead of using the Ruby hash syntax, you can define attributes using nested namespaces. This DSL may be more friendly to non-Ruby developers. It can safely be mixed-and-matched with the standard syntax.
         
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
       190 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       191 
     | 
    
         
            -
            # This is functionally the same as default['apache2']['config']['root'] = '/var/www'
         
     | 
| 
       192 
     | 
    
         
            -
            namespace 'apache2' do
         
     | 
| 
       193 
     | 
    
         
            -
              namespace 'config' do
         
     | 
| 
       194 
     | 
    
         
            -
                root '/var/www'
         
     | 
| 
       195 
     | 
    
         
            -
              end
         
     | 
| 
       196 
     | 
    
         
            -
            end
         
     | 
| 
       197 
     | 
    
         
            -
            ```
         
     | 
| 
       198 
     | 
    
         
            -
             
     | 
| 
       199 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       200 
     | 
    
         
            -
            # Specify multiple keys instead of nesting namespaces
         
     | 
| 
       201 
     | 
    
         
            -
            namespace 'apache2', 'config' do
         
     | 
| 
       202 
     | 
    
         
            -
              root '/var/www'
         
     | 
| 
       203 
     | 
    
         
            -
            end
         
     | 
| 
       204 
     | 
    
         
            -
            ```
         
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
       206 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       207 
     | 
    
         
            -
            # Specify different nested precedence levels
         
     | 
| 
       208 
     | 
    
         
            -
            namespace 'apache2', precedence: normal do
         
     | 
| 
       209 
     | 
    
         
            -
              namespace 'config', precedence: override do
         
     | 
| 
       210 
     | 
    
         
            -
                root '/var/www' #=> override['apache2']['config']['root'] = '/var/www'
         
     | 
| 
       211 
     | 
    
         
            -
              end
         
     | 
| 
       212 
     | 
    
         
            -
            end
         
     | 
| 
       213 
     | 
    
         
            -
            ```
         
     | 
| 
       214 
     | 
    
         
            -
             
     | 
| 
       215 
     | 
    
         
            -
            ### Constraints
         
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
       217 
     | 
    
         
            -
            - `constraints` - create a new constraint (or requirement) that can be used to test version validations.
         
     | 
| 
       218 
     | 
    
         
            -
            - `chef_version` - (DSL only) a wrapper for `version(Chef::VERSION)`
         
     | 
| 
       219 
     | 
    
         
            -
            - `version` - create a new version that can be used to test constraint validation.
         
     | 
| 
       220 
     | 
    
         
            -
             
     | 
| 
       221 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       222 
     | 
    
         
            -
             
     | 
| 
       223 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       224 
     | 
    
         
            -
            # Check if a version is satisfied by a constraint
         
     | 
| 
       225 
     | 
    
         
            -
            version('1.2.3').satisfies?('~> 1.2.0')
         
     | 
| 
       226 
     | 
    
         
            -
            ```
         
     | 
| 
       227 
     | 
    
         
            -
             
     | 
| 
       228 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       229 
     | 
    
         
            -
            # Check if a constraint is satisfied by a version
         
     | 
| 
       230 
     | 
    
         
            -
            constraint('~> 1.2.0').satisfied_by?('1.2.3')
         
     | 
| 
       231 
     | 
    
         
            -
            ```
         
     | 
| 
       232 
     | 
    
         
            -
             
     | 
| 
       233 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       234 
     | 
    
         
            -
            # Support multiple constraints
         
     | 
| 
       235 
     | 
    
         
            -
            version('1.2.3').satisfies?('> 1.2', '< 2.0')
         
     | 
| 
       236 
     | 
    
         
            -
            constraint('> 1.2', '< 2.0').satisfied_by?('1.2.3')
         
     | 
| 
       237 
     | 
    
         
            -
            ```
         
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       240 
     | 
    
         
            -
            # Only perform an operation if Chef is at a certain version
         
     | 
| 
       241 
     | 
    
         
            -
            package 'apache2' do
         
     | 
| 
       242 
     | 
    
         
            -
              not_if { chef_version.satisfies?('~> 11.0') } # Ignore Chef 11
         
     | 
| 
       243 
     | 
    
         
            -
            end
         
     | 
| 
       244 
     | 
    
         
            -
            ```
         
     | 
| 
       245 
     | 
    
         
            -
             
     | 
| 
       246 
     | 
    
         
            -
            ### Kernel
         
     | 
| 
       247 
     | 
    
         
            -
             
     | 
| 
       248 
     | 
    
         
            -
            - `require_chef_gem` - "safely" require a gem. Loading a gem with Chef is sometimes difficult and confusing. The errors that Chef produces are also sometimes not very intuitive. In the event you require a gem to exist on the system, you can use `require_chef_gem`, which will attempt to require the gem and then produce helpful output if the gem is not installed:
         
     | 
| 
       249 
     | 
    
         
            -
             
     | 
| 
       250 
     | 
    
         
            -
              ```
         
     | 
| 
       251 
     | 
    
         
            -
                Chef could not load the gem `#{name}'! You may need to install the gem
         
     | 
| 
       252 
     | 
    
         
            -
                manually with `gem install #{name}', or include a recipe before you can
         
     | 
| 
       253 
     | 
    
         
            -
                use this resource. Please consult the documentation for this cookbook
         
     | 
| 
       254 
     | 
    
         
            -
                for proper usage.
         
     | 
| 
       255 
     | 
    
         
            -
              ```
         
     | 
| 
       256 
     | 
    
         
            -
             
     | 
| 
       257 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       258 
     | 
    
         
            -
             
     | 
| 
       259 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       260 
     | 
    
         
            -
            # LWRP
         
     | 
| 
       261 
     | 
    
         
            -
            require_chef_gem 'pry'
         
     | 
| 
       262 
     | 
    
         
            -
            ```
         
     | 
| 
       263 
     | 
    
         
            -
             
     | 
| 
       264 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       265 
     | 
    
         
            -
            class Chef
         
     | 
| 
       266 
     | 
    
         
            -
              class Provider
         
     | 
| 
       267 
     | 
    
         
            -
                class MyProvider > Provider
         
     | 
| 
       268 
     | 
    
         
            -
                  require_chef_gem 'pry'
         
     | 
| 
       269 
     | 
    
         
            -
                end
         
     | 
| 
       270 
     | 
    
         
            -
              end
         
     | 
| 
       271 
     | 
    
         
            -
            end
         
     | 
| 
       272 
     | 
    
         
            -
            ```
         
     | 
| 
       273 
     | 
    
         
            -
             
     | 
| 
       274 
     | 
    
         
            -
            ### Init
         
     | 
| 
       275 
     | 
    
         
            -
             
     | 
| 
       276 
     | 
    
         
            -
            - `systemd?` - detect if init system is systemd
         
     | 
| 
       277 
     | 
    
         
            -
            - `upstart?` - detect if init system is upstart
         
     | 
| 
       278 
     | 
    
         
            -
            - `runit?` - detect if init system is runit
         
     | 
| 
       279 
     | 
    
         
            -
             
     | 
| 
       280 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       283 
     | 
    
         
            -
            systemd_service 'my-service' do
         
     | 
| 
       284 
     | 
    
         
            -
              description 'My Service'
         
     | 
| 
       285 
     | 
    
         
            -
              install do
         
     | 
| 
       286 
     | 
    
         
            -
                wanted_by 'multi-user.target'
         
     | 
| 
       287 
     | 
    
         
            -
              end
         
     | 
| 
       288 
     | 
    
         
            -
              service do
         
     | 
| 
       289 
     | 
    
         
            -
                exec_start '/usr/bin/myserviced'
         
     | 
| 
       290 
     | 
    
         
            -
              end
         
     | 
| 
       291 
     | 
    
         
            -
              action [:create, :enable, :start]
         
     | 
| 
       292 
     | 
    
         
            -
              only_if { systemd? }
         
     | 
| 
       293 
     | 
    
         
            -
            end
         
     | 
| 
       294 
     | 
    
         
            -
             
     | 
| 
       295 
     | 
    
         
            -
            cookbook_file '/etc/init/my-service.conf' do
         
     | 
| 
       296 
     | 
    
         
            -
              source 'my-service.conf'
         
     | 
| 
       297 
     | 
    
         
            -
              only_if { upstart? }
         
     | 
| 
       298 
     | 
    
         
            -
            end
         
     | 
| 
       299 
     | 
    
         
            -
            ```
         
     | 
| 
       300 
     | 
    
         
            -
             
     | 
| 
       301 
     | 
    
         
            -
            ### IP
         
     | 
| 
       302 
     | 
    
         
            -
             
     | 
| 
       303 
     | 
    
         
            -
            - `best_ip_for` - determine the best IP address for the given "other" node, preferring local IP addresses over public ones.
         
     | 
| 
       304 
     | 
    
         
            -
             
     | 
| 
       305 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       306 
     | 
    
         
            -
             
     | 
| 
       307 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       308 
     | 
    
         
            -
            redis = search('node', 'role:redis').first
         
     | 
| 
       309 
     | 
    
         
            -
             
     | 
| 
       310 
     | 
    
         
            -
            template '/tmp/config' do
         
     | 
| 
       311 
     | 
    
         
            -
              variables(
         
     | 
| 
       312 
     | 
    
         
            -
                ipaddress: best_ip_for(redis)
         
     | 
| 
       313 
     | 
    
         
            -
              )
         
     | 
| 
       314 
     | 
    
         
            -
            end
         
     | 
| 
       315 
     | 
    
         
            -
            ```
         
     | 
| 
       316 
     | 
    
         
            -
             
     | 
| 
       317 
     | 
    
         
            -
            ### Node
         
     | 
| 
       318 
     | 
    
         
            -
             
     | 
| 
       319 
     | 
    
         
            -
            Additional methods for the `node` object
         
     | 
| 
       320 
     | 
    
         
            -
             
     | 
| 
       321 
     | 
    
         
            -
            - `deep_fetch` - safely fetch a nested attribute.
         
     | 
| 
       322 
     | 
    
         
            -
            - `deep_fetch!` - fetch a nested attribute, raising a more semantic error if the key does not exist.
         
     | 
| 
       323 
     | 
    
         
            -
            - `in?` - determine if the node is in the given Chef environment.
         
     | 
| 
       324 
     | 
    
         
            -
             
     | 
| 
       325 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       326 
     | 
    
         
            -
             
     | 
| 
       327 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       328 
     | 
    
         
            -
            credentials = if node.in?('production')
         
     | 
| 
       329 
     | 
    
         
            -
                            Chef::EncryptedDataBag.new('...')
         
     | 
| 
       330 
     | 
    
         
            -
                          else
         
     | 
| 
       331 
     | 
    
         
            -
                            data_bag('...')
         
     | 
| 
       332 
     | 
    
         
            -
                          end
         
     | 
| 
       333 
     | 
    
         
            -
            ```
         
     | 
| 
       334 
     | 
    
         
            -
             
     | 
| 
       335 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       336 
     | 
    
         
            -
            node.deep_fetch('apache2', 'config', 'root') => node['apache2']['config']['root']
         
     | 
| 
       337 
     | 
    
         
            -
            ```
         
     | 
| 
       338 
     | 
    
         
            -
             
     | 
| 
       339 
     | 
    
         
            -
            ### Platform
         
     | 
| 
       340 
     | 
    
         
            -
             
     | 
| 
       341 
     | 
    
         
            -
            - `amazon_linux?`
         
     | 
| 
       342 
     | 
    
         
            -
            - `centos?`
         
     | 
| 
       343 
     | 
    
         
            -
            - `linux_mint?`
         
     | 
| 
       344 
     | 
    
         
            -
            - `oracle_linux?`
         
     | 
| 
       345 
     | 
    
         
            -
            - `redhat_enterprise_linux?`
         
     | 
| 
       346 
     | 
    
         
            -
            - `scientific_linux?`
         
     | 
| 
       347 
     | 
    
         
            -
            - `ubuntu?`
         
     | 
| 
       348 
     | 
    
         
            -
            - `solaris2?`
         
     | 
| 
       349 
     | 
    
         
            -
            - `aix?`
         
     | 
| 
       350 
     | 
    
         
            -
            - `smartos?`
         
     | 
| 
       351 
     | 
    
         
            -
            - `omnios?`
         
     | 
| 
       352 
     | 
    
         
            -
            - `raspbian?`
         
     | 
| 
       353 
     | 
    
         
            -
            - `nexus?`
         
     | 
| 
       354 
     | 
    
         
            -
            - `ios_xr?`
         
     | 
| 
       355 
     | 
    
         
            -
             
     | 
| 
       356 
     | 
    
         
            -
            There are also a series of dynamically defined matchers that map named operating system release versions and comparison operators in the form "#{platform}_#{operator}_#{name}?". For example:
         
     | 
| 
       357 
     | 
    
         
            -
             
     | 
| 
       358 
     | 
    
         
            -
            - `debian_after_squeeze?`
         
     | 
| 
       359 
     | 
    
         
            -
            - `linuxmint_after_or_at_olivia?`
         
     | 
| 
       360 
     | 
    
         
            -
            - `mac_os_x_lion?`
         
     | 
| 
       361 
     | 
    
         
            -
            - `centos_final?`
         
     | 
| 
       362 
     | 
    
         
            -
            - `ubuntu_before_lucid?`
         
     | 
| 
       363 
     | 
    
         
            -
            - `ubuntu_before_or_at_maverick?`
         
     | 
| 
       364 
     | 
    
         
            -
            - `solaris_10?`
         
     | 
| 
       365 
     | 
    
         
            -
            - `solaris_11?`
         
     | 
| 
       366 
     | 
    
         
            -
             
     | 
| 
       367 
     | 
    
         
            -
            To get a full list, run the following in IRB:
         
     | 
| 
       368 
     | 
    
         
            -
             
     | 
| 
       369 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       370 
     | 
    
         
            -
            require 'chef/sugar'
         
     | 
| 
       371 
     | 
    
         
            -
            puts Chef::Sugar::Platform.instance_methods
         
     | 
| 
       372 
     | 
    
         
            -
            ```
         
     | 
| 
       373 
     | 
    
         
            -
             
     | 
| 
       374 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       375 
     | 
    
         
            -
             
     | 
| 
       376 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       377 
     | 
    
         
            -
            if ubuntu?
         
     | 
| 
       378 
     | 
    
         
            -
              execute 'apt-get update'
         
     | 
| 
       379 
     | 
    
         
            -
            end
         
     | 
| 
       380 
     | 
    
         
            -
            ```
         
     | 
| 
       381 
     | 
    
         
            -
             
     | 
| 
       382 
     | 
    
         
            -
            ### Platform Family
         
     | 
| 
       383 
     | 
    
         
            -
             
     | 
| 
       384 
     | 
    
         
            -
            - `arch_linux?`
         
     | 
| 
       385 
     | 
    
         
            -
            - `debian?`
         
     | 
| 
       386 
     | 
    
         
            -
            - `fedora?`
         
     | 
| 
       387 
     | 
    
         
            -
            - `freebsd?`
         
     | 
| 
       388 
     | 
    
         
            -
            - `gentoo?`
         
     | 
| 
       389 
     | 
    
         
            -
            - `linux?`
         
     | 
| 
       390 
     | 
    
         
            -
            - `mac_os_x?`
         
     | 
| 
       391 
     | 
    
         
            -
            - `openbsd?`
         
     | 
| 
       392 
     | 
    
         
            -
            - `rhel?`
         
     | 
| 
       393 
     | 
    
         
            -
            - `slackware?`
         
     | 
| 
       394 
     | 
    
         
            -
            - `suse?`
         
     | 
| 
       395 
     | 
    
         
            -
            - `windows?`
         
     | 
| 
       396 
     | 
    
         
            -
            - `wrlinux?`
         
     | 
| 
       397 
     | 
    
         
            -
             
     | 
| 
       398 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       399 
     | 
    
         
            -
             
     | 
| 
       400 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       401 
     | 
    
         
            -
            node['attribute'] = if windows?
         
     | 
| 
       402 
     | 
    
         
            -
                                  'C:\Foo\BarDrive'
         
     | 
| 
       403 
     | 
    
         
            -
                                else
         
     | 
| 
       404 
     | 
    
         
            -
                                  '/foo/bar_drive'
         
     | 
| 
       405 
     | 
    
         
            -
                                end
         
     | 
| 
       406 
     | 
    
         
            -
            ```
         
     | 
| 
       407 
     | 
    
         
            -
             
     | 
| 
       408 
     | 
    
         
            -
            ### Ruby
         
     | 
| 
       409 
     | 
    
         
            -
             
     | 
| 
       410 
     | 
    
         
            -
            **Note:** The applies to the Ruby found at `node['languages']['ruby']`.
         
     | 
| 
       411 
     | 
    
         
            -
             
     | 
| 
       412 
     | 
    
         
            -
            - `ruby_20?`
         
     | 
| 
       413 
     | 
    
         
            -
            - `ruby_19?`
         
     | 
| 
       414 
     | 
    
         
            -
             
     | 
| 
       415 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       416 
     | 
    
         
            -
             
     | 
| 
       417 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       418 
     | 
    
         
            -
            log 'This has been known to fail on Ruby 2.0' if ruby_20?
         
     | 
| 
       419 
     | 
    
         
            -
            ```
         
     | 
| 
       420 
     | 
    
         
            -
             
     | 
| 
       421 
     | 
    
         
            -
            ### Run Context
         
     | 
| 
       422 
     | 
    
         
            -
             
     | 
| 
       423 
     | 
    
         
            -
            - `includes_recipe?` - determines if the current run context includes the recipe
         
     | 
| 
       424 
     | 
    
         
            -
             
     | 
| 
       425 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       426 
     | 
    
         
            -
            if includes_recipe?('apache2::default')
         
     | 
| 
       427 
     | 
    
         
            -
              apache_module 'my_module' do
         
     | 
| 
       428 
     | 
    
         
            -
                # ...
         
     | 
| 
       429 
     | 
    
         
            -
              end
         
     | 
| 
       430 
     | 
    
         
            -
            end
         
     | 
| 
       431 
     | 
    
         
            -
            ```
         
     | 
| 
       432 
     | 
    
         
            -
             
     | 
| 
       433 
     | 
    
         
            -
            ### Shell
         
     | 
| 
       434 
     | 
    
         
            -
             
     | 
| 
       435 
     | 
    
         
            -
            - `which`
         
     | 
| 
       436 
     | 
    
         
            -
            - `dev_null`
         
     | 
| 
       437 
     | 
    
         
            -
            - `installed?`
         
     | 
| 
       438 
     | 
    
         
            -
            - `installed_at_version?`
         
     | 
| 
       439 
     | 
    
         
            -
            - `version_for`
         
     | 
| 
       440 
     | 
    
         
            -
             
     | 
| 
       441 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       442 
     | 
    
         
            -
             
     | 
| 
       443 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       444 
     | 
    
         
            -
            log "Using `mongo` at `#{which('mongo')}`"
         
     | 
| 
       445 
     | 
    
         
            -
             
     | 
| 
       446 
     | 
    
         
            -
            if installed?('apt')
         
     | 
| 
       447 
     | 
    
         
            -
              execute 'apt-get update'
         
     | 
| 
       448 
     | 
    
         
            -
            end
         
     | 
| 
       449 
     | 
    
         
            -
             
     | 
| 
       450 
     | 
    
         
            -
            execute 'install[thing]' do
         
     | 
| 
       451 
     | 
    
         
            -
              command "... 2>&1 #{dev_null}"
         
     | 
| 
       452 
     | 
    
         
            -
              not_if  { installed_at_version?('thing', node['thing']['version']) }
         
     | 
| 
       453 
     | 
    
         
            -
            end
         
     | 
| 
       454 
     | 
    
         
            -
             
     | 
| 
       455 
     | 
    
         
            -
            log "Skipping git install, version is at #{version_for('mongo', '-v')}"
         
     | 
| 
       456 
     | 
    
         
            -
            ```
         
     | 
| 
       457 
     | 
    
         
            -
             
     | 
| 
       458 
     | 
    
         
            -
            ### Vagrant
         
     | 
| 
       459 
     | 
    
         
            -
             
     | 
| 
       460 
     | 
    
         
            -
            - `vagrant?`
         
     | 
| 
       461 
     | 
    
         
            -
             
     | 
| 
       462 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       463 
     | 
    
         
            -
             
     | 
| 
       464 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       465 
     | 
    
         
            -
            http_request 'http://...' do
         
     | 
| 
       466 
     | 
    
         
            -
              not_if { vagrant? }
         
     | 
| 
       467 
     | 
    
         
            -
            end
         
     | 
| 
       468 
     | 
    
         
            -
            ```
         
     | 
| 
       469 
     | 
    
         
            -
             
     | 
| 
       470 
     | 
    
         
            -
            ### Virtualization
         
     | 
| 
       471 
     | 
    
         
            -
             
     | 
| 
       472 
     | 
    
         
            -
            - `kvm?`
         
     | 
| 
       473 
     | 
    
         
            -
            - `lxc?`
         
     | 
| 
       474 
     | 
    
         
            -
            - `parallels?`
         
     | 
| 
       475 
     | 
    
         
            -
            - `virtualbox?`
         
     | 
| 
       476 
     | 
    
         
            -
            - `vmware?`
         
     | 
| 
       477 
     | 
    
         
            -
            - `openvz?`
         
     | 
| 
       478 
     | 
    
         
            -
             
     | 
| 
       479 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       480 
     | 
    
         
            -
             
     | 
| 
       481 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       482 
     | 
    
         
            -
            service 'ntpd' do
         
     | 
| 
       483 
     | 
    
         
            -
              action [:enable, :start]
         
     | 
| 
       484 
     | 
    
         
            -
              not_if { lxc? }
         
     | 
| 
       485 
     | 
    
         
            -
            end
         
     | 
| 
       486 
     | 
    
         
            -
            ```
         
     | 
| 
       487 
     | 
    
         
            -
             
     | 
| 
       488 
     | 
    
         
            -
            ### Filters
         
     | 
| 
       489 
     | 
    
         
            -
             
     | 
| 
       490 
     | 
    
         
            -
            - `at_compile_time` - accepts a block of resources to run at compile time
         
     | 
| 
       491 
     | 
    
         
            -
            - `before` - insert resource in the collection before the given resource
         
     | 
| 
       492 
     | 
    
         
            -
            - `after` - insert resource in the collection after the given resource
         
     | 
| 
       493 
     | 
    
         
            -
             
     | 
| 
       494 
     | 
    
         
            -
            #### Examples
         
     | 
| 
       495 
     | 
    
         
            -
             
     | 
| 
       496 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       497 
     | 
    
         
            -
            at_compile_time do
         
     | 
| 
       498 
     | 
    
         
            -
              package 'apache2'
         
     | 
| 
       499 
     | 
    
         
            -
            end
         
     | 
| 
       500 
     | 
    
         
            -
             
     | 
| 
       501 
     | 
    
         
            -
            # This is equivalent to
         
     | 
| 
       502 
     | 
    
         
            -
            package 'apache2' do
         
     | 
| 
       503 
     | 
    
         
            -
              action :nothing
         
     | 
| 
       504 
     | 
    
         
            -
            end.run_action(:install)
         
     | 
| 
       505 
     | 
    
         
            -
            ```
         
     | 
| 
       506 
     | 
    
         
            -
             
     | 
| 
       507 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       508 
     | 
    
         
            -
            before 'service[apache2]' do
         
     | 
| 
       509 
     | 
    
         
            -
              log 'I am before the apache 2 service fires!'
         
     | 
| 
       510 
     | 
    
         
            -
            end
         
     | 
| 
       511 
     | 
    
         
            -
            ```
         
     | 
| 
       512 
     | 
    
         
            -
             
     | 
| 
       513 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       514 
     | 
    
         
            -
            after 'service[apache2]' do
         
     | 
| 
       515 
     | 
    
         
            -
              log 'I am after the apache 2 service fires!'
         
     | 
| 
       516 
     | 
    
         
            -
            end
         
     | 
| 
       517 
     | 
    
         
            -
            ```
         
     | 
| 
       518 
     | 
    
         
            -
             
     | 
| 
       519 
     | 
    
         
            -
            ## License & Authors
         
     | 
| 
       520 
     | 
    
         
            -
             
     | 
| 
       521 
     | 
    
         
            -
            - Author: Seth Vargo (sethvargo@gmail.com)
         
     | 
| 
       522 
     | 
    
         
            -
             
     | 
| 
       523 
     | 
    
         
            -
            ```text
         
     | 
| 
       524 
     | 
    
         
            -
            Copyright 2013-2015 Seth Vargo
         
     | 
| 
       525 
     | 
    
         
            -
             
     | 
| 
       526 
     | 
    
         
            -
            Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
       527 
     | 
    
         
            -
            you may not use this file except in compliance with the License.
         
     | 
| 
       528 
     | 
    
         
            -
            You may obtain a copy of the License at
         
     | 
| 
       529 
     | 
    
         
            -
             
     | 
| 
       530 
     | 
    
         
            -
                http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
       531 
     | 
    
         
            -
             
     | 
| 
       532 
     | 
    
         
            -
            Unless required by applicable law or agreed to in writing, software
         
     | 
| 
       533 
     | 
    
         
            -
            distributed under the License is distributed on an "AS IS" BASIS,
         
     | 
| 
       534 
     | 
    
         
            -
            WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         
     | 
| 
       535 
     | 
    
         
            -
            See the License for the specific language governing permissions and
         
     | 
| 
       536 
     | 
    
         
            -
            limitations under the License.
         
     | 
| 
       537 
     | 
    
         
            -
            ```
         
     | 
| 
       538 
     | 
    
         
            -
             
     | 
| 
       539 
     | 
    
         
            -
            [gem]: https://rubygems.org/gems/chef-sugar
         
     | 
| 
       540 
     | 
    
         
            -
            [travis]: http://travis-ci.org/sethvargo/chef-sugar
         
     |