Cookbook file update not picked up by resource

Hi,

i am updating a file using cookbook file and then reading the contents of
the file ,

The file do get updated ion the client , but when i read the file the file
always read the previous content not the updated one,

I am not sure whats wrong here, please advise.

*Here is the properties file i am updating *
pbldejksu300:acc1,acc2
pdevecsas300:acc1,acc4
ppdsecsas300:acc1,acc2

here is the chef recipe

ookbook_file “/local_app/#{node[:tcat][:war_name]}.properties” do
source "#{node[:tcat][:war_name]}.properties"
mode 0777
owner "deploy"
group "deploy"
end

Chef::Log.info " host name is #{node[‘hostname’]} “
host=node[‘hostname’]
puts " hostname is #{host}“
output=Array.new
output1=cat /local_app//#{node[:tcat][:war_name]}.properties | grep -i "#{host}" | cut -d":" -f2
#output1.chomp
#output1.delete(”\n”)
#output1.rstrip()
output1.gsub!(/(\n*)$/, ‘’)
output=output1.split","
node.set[:acc_deploy]=output
#Chef::Log.info "Found correct value #{output1}, &&&& #{output} "
Chef::Log.info "Found correct value again #{node[‘acc_deploy’]} "

node[:acc_deploy].each do |data|
data.chomp
Chef::Log.info "Found correct value wow #{data} "

directory “/local_app/test/#{data}” do
owner "deploy"
group "deploy"
mode 0755
action :create
notifies :run, “bash[inst_tcat_#{data}]”, :immediately
end

bash “inst_tcat_#{data}” do
code <<-EOS
set -e -x
pwd
touch /local_app/test/#{data}/abc.txt
EOS
action :nothing
Chef::Log.info "Found correct value in the loop now #{data}"
end
end

Here is the client logs … as you see in the log it changed the file
content but still processed the old file data that was acc1,acc2,acc3

  • create a new cookbook_file /local_app/order-rest.properties
    — /local_app/order-rest.properties 2013-11-18
    10:56:04.408395557 -0800
    +++
    /var/chef/cache/cookbooks/base_tomcat/files/default/order-rest.properties
    2013-11-18 10:59:03.826165321 -0800
    @@ -1,3 +1,3 @@
    pbldejksu300:acc1,acc2
    -pdevecsas300:acc1,acc2,acc3
    +pdevecsas300:acc1,acc4
    ppdsecsas300:acc1,acc2
  • directory[/local_app/test/acc1] action
    create[2013-11-18T10:59:03-08:00] INFO: Processing
    directory[/local_app/test/acc1] action create (base_tomcat::new1 line 26)
    (up to date)

  • bash[inst_tcat_acc1] action nothing[2013-11-18T10:59:03-08:00] INFO:
    Processing bash[inst_tcat_acc1] action nothing (base_tomcat::new1 line 34)
    (up to date)

  • directory[/local_app/test/acc2] action
    create[2013-11-18T10:59:03-08:00] INFO: Processing
    directory[/local_app/test/acc2] action create (base_tomcat::new1 line 26)
    (up to date)

  • bash[inst_tcat_acc2] action nothing[2013-11-18T10:59:03-08:00] INFO:
    Processing bash[inst_tcat_acc2] action nothing (base_tomcat::new1 line 34)
    (up to date)

  • directory[/local_app/test/acc3] action
    create[2013-11-18T10:59:03-08:00] INFO: Processing
    directory[/local_app/test/acc3] action create (base_tomcat::new1 line 26)
    [2013-11-18T10:59:03-08:00] INFO: directory[/local_app/test/acc3] created
    directory /local_app/test/acc3

    • create new directory /local_app/test/acc3[2013-11-18T10:59:03-08:00]
      INFO: directory[/local_app/test/acc3] owner changed to 101
      [2013-11-18T10:59:03-08:00] INFO: directory[/local_app/test/acc3] group
      changed to 57001
      [2013-11-18T10:59:03-08:00] INFO: directory[/local_app/test/acc3] mode
      changed to 755

can anyone please help me point out the issue here,

I removed the node.set assuming thats the issue and is using a local
variable now, but its still the same issue,

Thanks
Manoj

On Mon, Nov 18, 2013 at 11:03 AM, Manoj Thakkar manoj.thakkar@gmail.comwrote:

Hi,

i am updating a file using cookbook file and then reading the contents of
the file ,

The file do get updated ion the client , but when i read the file the file
always read the previous content not the updated one,

I am not sure whats wrong here, please advise.

*Here is the properties file i am updating *
pbldejksu300:acc1,acc2
pdevecsas300:acc1,acc4
ppdsecsas300:acc1,acc2

here is the chef recipe

ookbook_file "/local_app/#{node[:tcat][:war_name]}.properties" do
source "#{node[:tcat][:war_name]}.properties"
mode 0777
owner "deploy"
group "deploy"
end

Chef::Log.info " host name is #{node['hostname']} "
host=node['hostname']
puts " hostname is #{host}"
output=Array.new
output1=cat /local_app//#{node[:tcat][:war_name]}.properties | grep -i "#{host}" | cut -d":" -f2
#output1.chomp
#output1.delete("\n")
#output1.rstrip()
output1.gsub!(/(\n*)$/, '')
output=output1.split","
node.set[:acc_deploy]=output
#Chef::Log.info "Found correct value #{output1}, &&&& #{output} "
Chef::Log.info "Found correct value again #{node['acc_deploy']} "

node[:acc_deploy].each do |data|
data.chomp
Chef::Log.info "Found correct value wow #{data} "

directory "/local_app/test/#{data}" do
owner "deploy"
group "deploy"
mode 0755
action :create
notifies :run, "bash[inst_tcat_#{data}]", :immediately
end

bash "inst_tcat_#{data}" do
code <<-EOS
set -e -x
pwd
touch /local_app/test/#{data}/abc.txt
EOS
action :nothing
Chef::Log.info "Found correct value in the loop now #{data}"
end
end

Here is the client logs .... as you see in the log it changed the file
content but still processed the old file data that was acc1,acc2,acc3

  • create a new cookbook_file /local_app/order-rest.properties
    --- /local_app/order-rest.properties 2013-11-18
    10:56:04.408395557 -0800
    +++
    /var/chef/cache/cookbooks/base_tomcat/files/default/order-rest.properties
    2013-11-18 10:59:03.826165321 -0800
    @@ -1,3 +1,3 @@
    pbldejksu300:acc1,acc2
    -pdevecsas300:acc1,acc2,acc3
    +pdevecsas300:acc1,acc4
    ppdsecsas300:acc1,acc2
  • directory[/local_app/test/acc1] action
    create[2013-11-18T10:59:03-08:00] INFO: Processing
    directory[/local_app/test/acc1] action create (base_tomcat::new1 line 26)
    (up to date)

  • bash[inst_tcat_acc1] action nothing[2013-11-18T10:59:03-08:00] INFO:
    Processing bash[inst_tcat_acc1] action nothing (base_tomcat::new1 line 34)
    (up to date)

  • directory[/local_app/test/acc2] action
    create[2013-11-18T10:59:03-08:00] INFO: Processing
    directory[/local_app/test/acc2] action create (base_tomcat::new1 line 26)
    (up to date)

  • bash[inst_tcat_acc2] action nothing[2013-11-18T10:59:03-08:00] INFO:
    Processing bash[inst_tcat_acc2] action nothing (base_tomcat::new1 line 34)
    (up to date)

  • directory[/local_app/test/acc3] action
    create[2013-11-18T10:59:03-08:00] INFO: Processing
    directory[/local_app/test/acc3] action create (base_tomcat::new1 line 26)
    [2013-11-18T10:59:03-08:00] INFO: directory[/local_app/test/acc3] created
    directory /local_app/test/acc3

    • create new directory /local_app/test/acc3[2013-11-18T10:59:03-08:00]
      INFO: directory[/local_app/test/acc3] owner changed to 101
      [2013-11-18T10:59:03-08:00] INFO: directory[/local_app/test/acc3] group
      changed to 57001
      [2013-11-18T10:59:03-08:00] INFO: directory[/local_app/test/acc3] mode
      changed to 755

Hello Manoj,

On Mon, 18 Nov 2013 11:03:48 -0800
Manoj Thakkar manoj.thakkar@gmail.com wrote:

[...]

here is the chef recipe

cookbook_file "/local_app/#{node[:tcat][:war_name]}.properties" do
source "#{node[:tcat][:war_name]}.properties"
mode 0777
owner "deploy"
group "deploy"
end

Chef::Log.info " host name is #{node['hostname']} "
host=node['hostname']
puts " hostname is #{host}"
output=Array.new
output1=cat /local_app//#{node[:tcat][:war_name]}.properties | grep -i "#{host}" | cut -d":" -f2

This cat command, will be run at compile time and the cookbook_file
resource above will be run (later) at converge/execution time.

If you want to read the new values you will need to read them at
converge time, perhaps using the ruby_block resource:

You can also run cookbook_file at compile time using #run_action
method, but this can a be a bit tricky.

https://wiki.opscode.com/display/chef/Evaluate+and+Run+Resources+at+Compile+Time;jsessionid=E91AD9698CE52D7640A2E1C17FB30201

Regards,

--
Xabier de Zuazo Oteiza
IT System Administrator - Onddo Labs S.L.
www.onddo.com

Public Key = http://www.onddo.com/xabier_zuazo.pub
Key Fingerprint = 8EFA 5B17 7275 5F1F 42B2 26B4 8E18 8B67 9DE1 9468