Is it not possible to use the mount resource to manage these entries in your fstab ?On Tue, Feb 26, 2013 at 5:40 AM, Joseph Bowman < " target="_blank"> > wrote:
I've had to do this a lot recently starting to set up our base builds as we move to chef. I've just used embedded bash scripts to get the results I've needed. This is just taking an example from you original email, please check for typos and such before using it. I wrote it out in this email, so it's completely untested.bash "update_fstab" docode <<-EOHEBS_VOL_DEV_CHECK = $(grep '#{node['mysql']['ebs_vol_dev']} /' /etc/fstab | wc -l)if [ $EBS_VOL_DEV_CHECK -lt 0 ]; thenecho '#{node['mysql']['ebs_vol_dev']} #{node['mysql']['mount_point']} #{node['mysql']['formatting']} noatime 0 0' >> /ec/fstabfiEOHend
You'd want to update the code block for each instance. I used this to manage files fstab, hosts and such. Albeit I'm much more comfortable with bash than ruby.On Tue, Feb 26, 2013 at 8:14 AM, Pete Cheslock < " target="_blank"> > 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 < " target="_blank"> > 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?
Archive powered by MHonArc 2.6.16.