- From: Juanje Ojeda Croissier <
>
- To: chef <
>
- Subject: [chef] Re: Re: Inserting multiple lines through Chef::Util::FileEdit
- Date: Tue, 26 Feb 2013 13:35:58 +0000
Chef::Util::FileEdit is a bit tricky and it must be the last option to
be used. I do use it myself sometimes, but I try to replace it with
templates or proper idempotence resources as soon as I can.
And for your case (/etc/fstab), there is already a resource to manage
the mount points that you may want to use:
http://docs.opscode.com/resource_mount.html
I hope this helps you.
On Tue, Feb 26, 2013 at 1:14 PM, Pete Cheslock
<
>
wrote:
>
Ive never used fileedit before. You should just use a template to render
>
out the file as you need. It will likely solve your problem.
>
>
>
>
On Feb 26, 2013, at 6:25 AM, Prajwal Manjunath
>
<
>
>
wrote:
>
>
> Hi,
>
>
>
> I'm trying to use the FileEdit util to modify my fstab, but it doesn't
>
> seem to work as expected.
>
>
>
> This is essentially my code:
>
>
>
> ruby_block "setup fstab" do
>
> not_if "cat /etc/fstab | grep #{node['mysql']['mount_point']} >
>
> /dev/null"
>
> block do
>
> f = Chef::Util::FileEdit.new('/etc/fstab')
>
> f.insert_line_if_no_match(/^#{node['mysql']['ebs_vol_dev']} /,
>
> "#{node['mysql']['ebs_vol_dev']} #{node['mysql']['mount_point']}
>
> #{node['mysql']['formatting']} noatime 0 0")
>
> f.insert_line_if_no_match(/^#{node['mysql']['ebs_data_dir']} /,
>
> "#{node['mysql']['ebs_data_dir']} #{node['mysql']['data_dir']} none bind")
>
> f.insert_line_if_no_match(/^#{node['mysql']['ebs_binlog_dir']} /,
>
> "#{node['mysql']['ebs_binlog_dir']} #{node['mysql']['data_dir']} none
>
> bind")
>
> f.write_file
>
> end
>
> notifies :run, "execute[mount_all]", :immediately
>
> end
>
>
>
> However, this only adds the first insert_line_if_no_match into the file. I
>
> confirmed this by removing the first command and it inserted the second
>
> one.
>
>
>
> Is this by design? Am I really not supposed to run multiple
>
> insert_line_if_no_match commands in one block on one file?
--
Juanje
http://about.me/juanje
Archive powered by MHonArc 2.6.16.