- From: Joseph Holsten <
>
- To:
- Cc: "
Dev" <
>
- Subject: [chef-dev] Re: Any equivalent of "puppet augeas" in Chef?
- Date: Mon, 16 Sep 2013 21:22:39 +0000
On 2013-09-16, at 06:11,
wrote:
>
I need to do in-place file editing of config files using Chef. For now, i
>
could
>
see that we can append data to the config files using the "bash" resource.
>
But,
>
i need to change specific variables in config files using Chef.
>
>
I could see that there's a handy tool called augeas in puppet that clearly
>
performs the above requirement. But, i couldn't come up with anything in
>
Chef.
>
>
So, is there any way this could be done in Chef?
There isn't an augeas resource provided by chef, and cursory searching
doesn't reveal a cookbook with one. But you could certainly write one. Here's
some inspiration:
Salt provides an augeas 'state' (like resource) with one 'command' (like
action): setvalue. It also provides a 'module' (like library) that supports
get, ls, match, remove, setvalue & tree.
http://docs.saltstack.com/ref/modules/all/salt.modules.augeas_cfg.html
http://docs.saltstack.com/ref/states/all/salt.states.augeas.html
Puppet has very thorough complete doc for using the augeas 'type' (like
resource) in puppet:
http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Augeas
http://docs.puppetlabs.com/references/latest/type.html#augeas
I'd like to see a chef resource that does things like:
augeas '/files/etc/ssh/sshd_config/AcceptEnv/01' do
value 'FOO'
action :set
end
augeas 'accept foo env in sshd' do
path '/files/etc/ssh/sshd_config/AcceptEnv/01'
value 'FOO'
action :set
end
augeas "/files/etc/ssh/sshd_config/AcceptEnv/01" do
action :rm
end
Looks like there are some decent augeas bindings in ruby-augeas:
https://github.com/hercules-team/ruby-augeas
I think you could get dangerously far with something like
require 'ruby-augeas'
action :set do
Augeas::open do |aug|
aug.set(new_resource.path, new_resource.path)
unless aug.save
raise IOError, "Failed to save changes"
end
end
new_resource.updated_by_last_action(true)
end
action :rm do
Augeas::open do |aug|
aug.rm(new_resource.path)
unless aug.save
raise IOError, "Failed to save changes"
end
end
new_resource.updated_by_last_action(true)
end
I'd still want a recipe to install augeas and the ruby-augeas gem, plus some
actual error handling, really checking if the resource was updated, and
converge_by/why-run support would be awesome.
--
~j
Attachment:
signature.asc
Description: Message signed with OpenPGP using GPGMail
Archive powered by MHonArc 2.6.16.