here is a piece of my chef ruby code and I am trying to pass a value from one block to other block. We have multiple ports running on the server, below code will check the port and if its not running it will try to execute the 2nd block. I have attached the code and error. Please help where i am going wrong.
ports.each do |port|
bash "Check_port_running_#{port}" do
code <<-EOH
pidval=$(ps -ef | grep /opt/redis/src/redis-server | grep *:#{port} | grep -vc grep)
if (($pidval == 0));then
portval_#{port}=true
else
portval_#{port}=false
fi
EOH
end
bash "Starting_redis_after_crash_for_port - #{port}" do
only_if { "portval_#{port}" }
code <<-EOH
rm -f #{port}.pid
sudo service redis@#{port} start
EOH
end
end
Error : Getting below error
================================================================================
Error executing action `run` on resource 'bash[Starting_redis_after_crash_for_port - 54321]'
================================================================================
Errno::ENOENT
-------------
No such file or directory - portval_54321
Resource Declaration:
---------------------
# In /tmp/kitchen/cache/cookbooks/csg_orderservices_redis/recipes/configure.rb
184: bash "Starting_redis_after_crash_for_port - #{port}" do
185: only_if "portval_#{port}"
186: code <<-EOH
187: rm -f #{port}.pid
188: sudo service redis@#{port} start
189: EOH
190: end
191: end
Compiled Resource:
------------------
# Declared in /tmp/kitchen/cache/cookbooks/csg_orderservices_redis/recipes/configure.rb:184:in `block in from_file'
bash("Starting_redis_after_crash_for_port - 54321") do
action [:run]
default_guard_interpreter :default
backup 5
interpreter "bash"
declared_type :bash
cookbook_name "csg_orderservices_redis"
recipe_name "configure"
code " rm -f 54321.pid\n sudo service redis@54321 start\n"
domain nil
user nil
only_if "portval_54321"
end