Module: Chef::Sugar::DSL

Defined in:
lib/chef/sugar/ip.rb,
lib/chef/sugar/ruby.rb,
lib/chef/sugar/cloud.rb,
lib/chef/sugar/shell.rb,
lib/chef/sugar/docker.rb,
lib/chef/sugar/filters.rb,
lib/chef/sugar/vagrant.rb,
lib/chef/sugar/data_bag.rb,
lib/chef/sugar/platform.rb,
lib/chef/sugar/constraints.rb,
lib/chef/sugar/run_context.rb,
lib/chef/sugar/architecture.rb,
lib/chef/sugar/virtualization.rb,
lib/chef/sugar/platform_family.rb

Instance Method Summary collapse

Instance Method Details

#_32_bit?Boolean Also known as: i386?

Returns:

  • (Boolean)

See Also:



50
# File 'lib/chef/sugar/architecture.rb', line 50

def _32_bit?; Chef::Sugar::Architecture._32_bit?(node); end

#_64_bit?Boolean

Returns:

  • (Boolean)

See Also:



47
# File 'lib/chef/sugar/architecture.rb', line 47

def _64_bit?; Chef::Sugar::Architecture._64_bit?(node); end

#after(identifier, &block) ⇒ Object

Dynamically insert resources after an existing resource in the resource_collection.

after 'service[apache2]' do
  template '/etc/apache2/thing.conf' do
    source '...'
  end
end

Examples:

Write a custom template after the apache2 service actions

are run

Parameters:

  • identifier (String)

    the resource[name] identifier string



148
149
150
# File 'lib/chef/sugar/filters.rb', line 148

def after(identifier, &block)
  Chef::Sugar::Filters::Injector.new(self, identifier, :after).evaluate(&block)
end

#azure?Boolean

Returns:

  • (Boolean)

See Also:



159
# File 'lib/chef/sugar/cloud.rb', line 159

def azure?; Chef::Sugar::Cloud.azure?(node); end

#before(identifier, &block) ⇒ Object

Dynamically insert resources before an existing resource in the resource_collection.

before 'service[apache2]' do
  template '/etc/apache2/thing.conf' do
    source '...'
  end
end

Examples:

Write a custom template before the apache2 service actions

are run

Parameters:

  • identifier (String)

    the resource[name] identifier string



128
129
130
# File 'lib/chef/sugar/filters.rb', line 128

def before(identifier, &block)
  Chef::Sugar::Filters::Injector.new(self, identifier, :before).evaluate(&block)
end

#best_ip_for(other) ⇒ Object

See Also:



45
# File 'lib/chef/sugar/ip.rb', line 45

def best_ip_for(other); Chef::Sugar::IP.best_ip_for(node, other); end

#chef_versionChef::Sugar::Constraints::Version

This wrapper/convenience method is only available in the recipe DSL. It creates a new version object from the VERSION.

Examples:

Check if Chef 11+

chef_version.satisfies?('>= 11.0.0')

Returns:



156
157
158
# File 'lib/chef/sugar/constraints.rb', line 156

def chef_version
  version(Chef::VERSION)
end

#cloud?Boolean

Returns:

  • (Boolean)

See Also:



134
# File 'lib/chef/sugar/cloud.rb', line 134

def cloud?; Chef::Sugar::Cloud.cloud?(node); end

#cloudstack?Boolean

Returns:

  • (Boolean)

See Also:



156
# File 'lib/chef/sugar/cloud.rb', line 156

def cloudstack?; Chef::Sugar::Cloud.cloudstack?(node); end

#compile_time(&block) ⇒ Object

Dynamically run resources specified in the block during the compilation phase, instead of the convergence phase.

Examples:

The old way

package('apache2') do
  action :nothing
end.run_action(:install)

The new way

compile_time do
  package('apache2')
end

Resource actions are run in order

compile_time do
  service 'apache2' do
    action [:enable, :start] # run_action(:enable), run_action(:start)
  end
end


108
109
110
# File 'lib/chef/sugar/filters.rb', line 108

def compile_time(&block)
  Chef::Sugar::Filters::CompileTime.new(self).evaluate(&block)
end

#constraint(*constraints) ⇒ Object



142
143
144
# File 'lib/chef/sugar/constraints.rb', line 142

def constraint(*constraints)
  Chef::Sugar::Constraints.constraint(*constraints)
end

#dev_nullObject

See Also:



131
# File 'lib/chef/sugar/shell.rb', line 131

def dev_null; Chef::Sugar::Shell.dev_null(node); end

#docker?Boolean

Returns:

  • (Boolean)

See Also:



37
# File 'lib/chef/sugar/docker.rb', line 37

def docker?; Chef::Sugar::Docker.docker?(node); end

#ec2?Boolean

Returns:

  • (Boolean)

See Also:



137
# File 'lib/chef/sugar/cloud.rb', line 137

def ec2?; Chef::Sugar::Cloud.ec2?(node); end

#encrypted_data_bag_item(bag, id, secret = nil) ⇒ Object



98
99
100
# File 'lib/chef/sugar/data_bag.rb', line 98

def encrypted_data_bag_item(bag, id, secret = nil)
  Chef::Sugar::DataBag.encrypted_data_bag_item(bag, id, secret)
end

#encrypted_data_bag_item_for_environment(bag, id, secret = nil) ⇒ Object



103
104
105
# File 'lib/chef/sugar/data_bag.rb', line 103

def encrypted_data_bag_item_for_environment(bag, id, secret = nil)
  Chef::Sugar::DataBag.encrypted_data_bag_item_for_environment(node, bag, id, secret)
end

#eucalyptus?Boolean Also known as: euca?

Returns:

  • (Boolean)

See Also:



146
# File 'lib/chef/sugar/cloud.rb', line 146

def eucalyptus?; Chef::Sugar::Cloud.eucalyptus?(node); end

#gce?Boolean

Returns:

  • (Boolean)

See Also:



140
# File 'lib/chef/sugar/cloud.rb', line 140

def gce?; Chef::Sugar::Cloud.gce?(node); end

#includes_recipe?(recipe_name) ⇒ Boolean Also known as: include_recipe?

Returns:

  • (Boolean)

See Also:



35
36
37
# File 'lib/chef/sugar/run_context.rb', line 35

def includes_recipe?(recipe_name)
  Chef::Sugar::RunContext.includes_recipe?(node, recipe_name)
end

#installed?(cmd) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



134
# File 'lib/chef/sugar/shell.rb', line 134

def installed?(cmd); Chef::Sugar::Shell.installed?(cmd); end

#installed_at_version?(cmd, version, flag = '--version') ⇒ Boolean

Returns:

  • (Boolean)

See Also:



137
138
139
# File 'lib/chef/sugar/shell.rb', line 137

def installed_at_version?(cmd, version, flag = '--version')
  Chef::Sugar::Shell.installed_at_version?(cmd, version, flag)
end

#linode?Boolean

Returns:

  • (Boolean)

See Also:



150
# File 'lib/chef/sugar/cloud.rb', line 150

def linode?; Chef::Sugar::Cloud.linode?(node); end

#lxc?Boolean

Returns:

  • (Boolean)

See Also:



51
# File 'lib/chef/sugar/virtualization.rb', line 51

def lxc?; Chef::Sugar::Virtualization.lxc?(node); end

#openstack?Boolean

Returns:

  • (Boolean)

See Also:



153
# File 'lib/chef/sugar/cloud.rb', line 153

def openstack?; Chef::Sugar::Cloud.openstack?(node); end

#rackspace?Boolean

Returns:

  • (Boolean)

See Also:



143
# File 'lib/chef/sugar/cloud.rb', line 143

def rackspace?; Chef::Sugar::Cloud.rackspace?(node); end

#ruby_19?Boolean

Returns:

  • (Boolean)

See Also:



48
# File 'lib/chef/sugar/ruby.rb', line 48

def ruby_19?; Chef::Sugar::Ruby.ruby_19?(node); end

#ruby_20?Boolean

Returns:

  • (Boolean)

See Also:



45
# File 'lib/chef/sugar/ruby.rb', line 45

def ruby_20?; Chef::Sugar::Ruby.ruby_20?(node); end

#vagrant?Boolean

Returns:

  • (Boolean)

See Also:



74
# File 'lib/chef/sugar/vagrant.rb', line 74

def vagrant?; Chef::Sugar::Vagrant.vagrant?(node); end

#version(version) ⇒ Object



137
138
139
# File 'lib/chef/sugar/constraints.rb', line 137

def version(version)
  Chef::Sugar::Constraints::Version.new(version)
end

#version_for(cmd, flag = '--version') ⇒ Object

See Also:



142
143
144
# File 'lib/chef/sugar/shell.rb', line 142

def version_for(cmd, flag = '--version')
  Chef::Sugar::Shell.version_for(cmd, flag)
end

#vmware?Boolean

Returns:

  • (Boolean)

See Also:



54
# File 'lib/chef/sugar/virtualization.rb', line 54

def vmware?; Chef::Sugar::Virtualization.vmware?(node); end

#which(cmd) ⇒ Object

See Also:



128
# File 'lib/chef/sugar/shell.rb', line 128

def which(cmd); Chef::Sugar::Shell.which(cmd); end