Module: Chef::Sugar::DSL

Defined in:
lib/chef/sugar/ip.rb,
lib/chef/sugar/init.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/kitchen.rb,
lib/chef/sugar/vagrant.rb,
lib/chef/sugar/data_bag.rb,
lib/chef/sugar/platform.rb,
lib/chef/sugar/run_context.rb,
lib/chef/sugar/architecture.rb,
lib/chef/sugar/virtualization.rb,
lib/chef/sugar/constraints_dsl.rb,
lib/chef/sugar/platform_family.rb

Instance Method Summary collapse

Instance Method Details

#_32_bit?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#_64_bit?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#aarch64?Boolean

Returns:

  • (Boolean)

See Also:



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

def aarch64?; Chef::Sugar::Architecture.aarch64?(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

#armhf?Boolean

Returns:

  • (Boolean)

See Also:

  • Architecture#arm?


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

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

#at_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

at_compile_time do
  package('apache2')
end

Resource actions are run in order

at_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 at_compile_time(&block)
  Chef::Sugar::Filters::AtCompileTime.new(self).evaluate(&block)
end

#azure?Boolean

Returns:

  • (Boolean)

See Also:



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

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:



78
79
80
# File 'lib/chef/sugar/constraints_dsl.rb', line 78

def chef_version
  version(Chef::VERSION)
end

#cloud?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#cloudstack?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#constraint(*constraints) ⇒ Object



64
65
66
# File 'lib/chef/sugar/constraints_dsl.rb', line 64

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

#data_bag_item_for_environment(bag, id) ⇒ Object



141
142
143
# File 'lib/chef/sugar/data_bag.rb', line 141

def data_bag_item_for_environment(bag, id)
  Chef::Sugar::DataBag.data_bag_item_for_environment(node, bag, id)
end

#dev_nullObject

See Also:



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

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

#digitalocean?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#docker?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#ec2?Boolean

Returns:

  • (Boolean)

See Also:



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

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

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



131
132
133
# File 'lib/chef/sugar/data_bag.rb', line 131

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



136
137
138
# File 'lib/chef/sugar/data_bag.rb', line 136

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:



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

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

#gce?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#i386?Boolean

Returns:

  • (Boolean)

See Also:



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

def i386?; Chef::Sugar::Architecture.i386?(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:



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

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

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

Returns:

  • (Boolean)

See Also:



147
148
149
# File 'lib/chef/sugar/shell.rb', line 147

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

#intel?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#kitchen?Boolean

Returns:

  • (Boolean)

See Also:



41
# File 'lib/chef/sugar/kitchen.rb', line 41

def kitchen?; Chef::Sugar::Kitchen.kitchen?(node); end

#kvm?Boolean

Returns:

  • (Boolean)

See Also:



111
112
113
# File 'lib/chef/sugar/virtualization.rb', line 111

def kvm?
  Chef::Sugar::Virtualization.kvm?(node)
end

#linode?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#lxc?Boolean

Returns:

  • (Boolean)

See Also:



116
117
118
# File 'lib/chef/sugar/virtualization.rb', line 116

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

#openstack?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#openvz?Boolean

Returns:

  • (Boolean)

See Also:



136
137
138
# File 'lib/chef/sugar/virtualization.rb', line 136

def openvz?
  Chef::Sugar::Virtualization.openvz?(node)
end

#parallels?Boolean

Returns:

  • (Boolean)

See Also:



121
122
123
# File 'lib/chef/sugar/virtualization.rb', line 121

def parallels?
  Chef::Sugar::Virtualization.parallels?(node)
end

#physical?Boolean

Returns:

  • (Boolean)

See Also:



146
147
148
# File 'lib/chef/sugar/virtualization.rb', line 146

def physical?
  Chef::Sugar::Virtualization.physical?(node)
end

#powerpc?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#ppc64?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#ppc64le?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#rackspace?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#runit?Boolean

Returns:

  • (Boolean)

See Also:



58
# File 'lib/chef/sugar/init.rb', line 58

def runit?; Chef::Sugar::Init.runit?(node); end

#s390x?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#softlayer?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#sparc?Boolean

Returns:

  • (Boolean)

See Also:



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

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

#systemd?Boolean

Returns:

  • (Boolean)

See Also:



52
# File 'lib/chef/sugar/init.rb', line 52

def systemd?; Chef::Sugar::Init.systemd?(node); end

#upstart?Boolean

Returns:

  • (Boolean)

See Also:



55
# File 'lib/chef/sugar/init.rb', line 55

def upstart?; Chef::Sugar::Init.upstart?(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



59
60
61
# File 'lib/chef/sugar/constraints_dsl.rb', line 59

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

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

See Also:



152
153
154
# File 'lib/chef/sugar/shell.rb', line 152

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

#virtual?Boolean

Returns:

  • (Boolean)

See Also:



141
142
143
# File 'lib/chef/sugar/virtualization.rb', line 141

def virtual?
  Chef::Sugar::Virtualization.virtual?(node)
end

#virtualbox?Boolean

Returns:

  • (Boolean)

See Also:



126
127
128
# File 'lib/chef/sugar/virtualization.rb', line 126

def virtualbox?
  Chef::Sugar::Virtualization.virtualbox?(node)
end

#vmware?Boolean

Returns:

  • (Boolean)

See Also:



131
132
133
# File 'lib/chef/sugar/virtualization.rb', line 131

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

#which(cmd) ⇒ Object

See Also:



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

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