Category Archives: Systems Automation

Opscode Chef Xtra: Obtaining network interface data

It is somewhat of a challenge to obtain interface information out of the data Ohai makes available for network interfaces. For information only about inet addresses, the following works: node_addresses = {} node[:network][:interfaces].each do |iface, vals| vals[:addresses].each do |addr, h| next unless h[’family’] == ‘inet’ && !addr.match(’127.0.0.1′) iface_data = Hash.new iface_data = h.dup iface_data[’address’] = [...]

Getting a little crazy with FileEdit

In case there is any doubt, you can go nuts with Chef::Util::FileEdit. If one is using search_file_replace, internally it is simply: new_contents << ((method == 1) ? replace : line.gsub!(exp, replace)) Meaning if need be, I can do something silly: ruby_block ‘fix remi.repo’ do action :nothing block do f = Chef::Util::FileEdit.new(’/etc/yum.repos.d/remi.repo’) f.search_file_replace(/\$releasever/, ‘%i’ % major) [...]

Opscode Chef Xtra: A Deletable Template via a Definition

While there is no delete action recognized by the Chef template resource, it is possible to fake it using a definition. For example, a definition for managing a configuration file for the multifaceted DNS server dnsmasq might look like the following: define :dnsmasq_conf, :enable => true, :template => ‘dnsmasq.conf.erb’ do include_recipe ‘dnsmasq’   conffile = [...]

Opscode Chef Xtra: Achieving Idempotence in execute Resource

The certainty of outcome offered by other Chef resources is notably lacking from the execute Resource, for Chef has no way of knowing the consequences of the provided shell script fragment. Fortunately, it’s possible to ensure idempotent behavior with the appropriate application of care. As an example, perhaps one needs to load several database dump [...]