Inserting multiple lines through Chef::Util::FileEdit

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?

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 prajwal@elitmus.com 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?

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:

I hope this helps you.

On Tue, Feb 26, 2013 at 1:14 PM, Pete Cheslock petecheslock@gmail.com 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 prajwal@elitmus.com 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

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" do
code <<-EOH
EBS_VOL_DEV_CHECK = $(grep '#{node['mysql']['ebs_vol_dev']} /'
/etc/fstab | wc -l)
if [ $EBS_VOL_DEV_CHECK -lt 0 ]; then
echo '#{node['mysql']['ebs_vol_dev']} #{node['mysql']['mount_point']}
#{node['mysql']['formatting']} noatime 0 0' >> /ec/fstab
fi
EOH
end

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 petecheslock@gmail.comwrote:

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 prajwal@elitmus.com
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?

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 bowman.joseph@gmail.comwrote:

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" do
code <<-EOH
EBS_VOL_DEV_CHECK = $(grep '#{node['mysql']['ebs_vol_dev']} /'
/etc/fstab | wc -l)
if [ $EBS_VOL_DEV_CHECK -lt 0 ]; then
echo '#{node['mysql']['ebs_vol_dev']}
#{node['mysql']['mount_point']} #{node['mysql']['formatting']} noatime 0 0'

/ec/fstab
fi
EOH
end

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 petecheslock@gmail.comwrote:

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 prajwal@elitmus.com
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?

About the mount resource:
This was some time ago, but I couldn't get the mount resource to create an
fstab entry. My action is "action [:mount, :enable]", but it doesn't seem
to do anything to the fstab. I haven't tried to debug it in a while, I'll
dig into it and see what was the problem that led me to use FileEdit.

If it helps, what I'm mounting is an amazon EBS volume with non-default
formatting (xfs), attached to my instance during runtime by the right-aws
gem.

On Wed, Feb 27, 2013 at 1:44 AM, Jesse Nelson spheromak@gmail.com wrote:

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 bowman.joseph@gmail.comwrote:

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" do
code <<-EOH
EBS_VOL_DEV_CHECK = $(grep '#{node['mysql']['ebs_vol_dev']} /'
/etc/fstab | wc -l)
if [ $EBS_VOL_DEV_CHECK -lt 0 ]; then
echo '#{node['mysql']['ebs_vol_dev']}
#{node['mysql']['mount_point']} #{node['mysql']['formatting']} noatime 0 0'

/ec/fstab
fi
EOH
end

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 petecheslock@gmail.comwrote:

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 prajwal@elitmus.com
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?

Also look at the line cookbook http://ckbk.it/line that wraps that patterns
in a way that is somewhat easier to use.

On Wed, Feb 27, 2013 at 6:10 AM, Prajwal Manjunath prajwal@elitmus.comwrote:

About the mount resource:
This was some time ago, but I couldn't get the mount resource to create an
fstab entry. My action is "action [:mount, :enable]", but it doesn't seem
to do anything to the fstab. I haven't tried to debug it in a while, I'll
dig into it and see what was the problem that led me to use FileEdit.

If it helps, what I'm mounting is an amazon EBS volume with non-default
formatting (xfs), attached to my instance during runtime by the right-aws
gem.

On Wed, Feb 27, 2013 at 1:44 AM, Jesse Nelson spheromak@gmail.com wrote:

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 bowman.joseph@gmail.comwrote:

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" do
code <<-EOH
EBS_VOL_DEV_CHECK = $(grep '#{node['mysql']['ebs_vol_dev']} /'
/etc/fstab | wc -l)
if [ $EBS_VOL_DEV_CHECK -lt 0 ]; then
echo '#{node['mysql']['ebs_vol_dev']}
#{node['mysql']['mount_point']} #{node['mysql']['formatting']} noatime 0 0'

/ec/fstab
fi
EOH
end

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 petecheslock@gmail.comwrote:

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 prajwal@elitmus.com
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?

The methode 'insert_line_if_no_match(...)' calls only the private one 'search_match(...)' with the right parameters. This methode makes his changes only in the variable 'contents'. Try to make a 'f.write_file' after every call of 'insert_line_if_no_match(...)'.

About the mount resource:
This was some time ago, but I couldn't get the mount resource to create an
fstab entry. My action is "action [:mount, :enable]", but it doesn't seem
to do anything to the fstab. I haven't tried to debug it in a while, I'll
dig into it and see what was the problem that led me to use FileEdit.

If it helps, what I'm mounting is an amazon EBS volume with non-default
formatting (xfs), attached to my instance during runtime by the right-aws
gem.

On Wed, Feb 27, 2013 at 1:44 AM, Jesse Nelson spheromak@gmail.com wrote:

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
bowman.joseph@gmail.comwrote:

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" do
code <<-EOH
EBS_VOL_DEV_CHECK = $(grep '#{node['mysql']['ebs_vol_dev']} /'
/etc/fstab | wc -l)
if [ $EBS_VOL_DEV_CHECK -lt 0 ]; then
echo '#{node['mysql']['ebs_vol_dev']}
#{node['mysql']['mount_point']} #{node['mysql']['formatting']} noatime
0 0'

/ec/fstab
fi
EOH
end

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
petecheslock@gmail.comwrote:

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 prajwal@elitmus.com
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?

Hontestly, these libs are in a need of some love.
I have some "file a ticket" tasks in my GTD that I plan to get around to soon.
-s

On Wed, Feb 27, 2013 at 3:30 AM, Oleg Volotov oleg.volotov@gmx.de wrote:

The methode 'insert_line_if_no_match(...)' calls only the private one 'search_match(...)' with the right parameters. This methode makes his changes only in the variable 'contents'. Try to make a 'f.write_file' after every call of 'insert_line_if_no_match(...)'.

About the mount resource:
This was some time ago, but I couldn't get the mount resource to create an
fstab entry. My action is "action [:mount, :enable]", but it doesn't seem
to do anything to the fstab. I haven't tried to debug it in a while, I'll
dig into it and see what was the problem that led me to use FileEdit.

If it helps, what I'm mounting is an amazon EBS volume with non-default
formatting (xfs), attached to my instance during runtime by the right-aws
gem.

On Wed, Feb 27, 2013 at 1:44 AM, Jesse Nelson spheromak@gmail.com wrote:

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
bowman.joseph@gmail.comwrote:

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" do
code <<-EOH
EBS_VOL_DEV_CHECK = $(grep '#{node['mysql']['ebs_vol_dev']} /'
/etc/fstab | wc -l)
if [ $EBS_VOL_DEV_CHECK -lt 0 ]; then
echo '#{node['mysql']['ebs_vol_dev']}
#{node['mysql']['mount_point']} #{node['mysql']['formatting']} noatime
0 0'

/ec/fstab
fi
EOH
end

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
petecheslock@gmail.comwrote:

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 prajwal@elitmus.com
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?

I did note that the uncomment line if match LWRP was not completely
implemented :slight_smile:

Cheers,

AJ

On 28 February 2013 08:00, Sean OMeara someara@gmail.com wrote:

Hontestly, these libs are in a need of some love.
I have some "file a ticket" tasks in my GTD that I plan to get around to soon.
-s

On Wed, Feb 27, 2013 at 3:30 AM, Oleg Volotov oleg.volotov@gmx.de wrote:

The methode 'insert_line_if_no_match(...)' calls only the private one 'search_match(...)' with the right parameters. This methode makes his changes only in the variable 'contents'. Try to make a 'f.write_file' after every call of 'insert_line_if_no_match(...)'.

About the mount resource:
This was some time ago, but I couldn't get the mount resource to create an
fstab entry. My action is "action [:mount, :enable]", but it doesn't seem
to do anything to the fstab. I haven't tried to debug it in a while, I'll
dig into it and see what was the problem that led me to use FileEdit.

If it helps, what I'm mounting is an amazon EBS volume with non-default
formatting (xfs), attached to my instance during runtime by the right-aws
gem.

On Wed, Feb 27, 2013 at 1:44 AM, Jesse Nelson spheromak@gmail.com wrote:

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
bowman.joseph@gmail.comwrote:

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" do
code <<-EOH
EBS_VOL_DEV_CHECK = $(grep '#{node['mysql']['ebs_vol_dev']} /'
/etc/fstab | wc -l)
if [ $EBS_VOL_DEV_CHECK -lt 0 ]; then
echo '#{node['mysql']['ebs_vol_dev']}
#{node['mysql']['mount_point']} #{node['mysql']['formatting']} noatime
0 0'

/ec/fstab
fi
EOH
end

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
petecheslock@gmail.comwrote:

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 prajwal@elitmus.com
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?