I need to store the IP which is the result of a bash resource into a variable that I can use later.
My code looks like this:
sentinel_ip=" "
sentinel_hostname=" "
sentinel_machine = search(:node, "role:redis AND chef_environment:#{chef_env} AND team:#{team} AND node_type:sentinel")
sentinel_machine.each do |nodeobj_sentinel|
sentinel_ip << nodeobj_sentinel['ipaddress']
sentinel_hostname << nodeobj_sentinel.name
end
execute 'get master' do
command = "redis-cli -h #{sentinel_hostname} -p 26379 info | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' "
action :run
# I'll store the result of the above command in master_ip variable
master_ip << node['ipaddress']
end
#here I need to use the master_ip to connect to it
bash 'update config in runtime' do
code <<-EOH
redis-cli -h #{master_ip} -p #{defaultport} -a #{auth} config set #{runtime_config}
redis-cli -h #{master_ip} -p #{defaultport} -a #{auth} config rewrite
EOH
not_if { runtime_config.empty?}
end
Basically, if I get any master_ip from “get_master” execute resource, I pass it to the bash block below to use it, in order to update redis at runtime.
When I get something in master_ip, I’ll continue the rest of my recipe.
Anyway, the result of running ‘get master’ execute block above ends with
Compiling Cookbooks...
[2017-10-29T10:26:58+00:00] WARN: nodeobj_sentinel: node[clj-lc-tstrds03]
[2017-10-29T10:26:58+00:00] WARN: nodeobj_sentinel ip: 10.111.200.25
[2017-10-29T10:26:58+00:00] WARN: nodeobj_sentinel name: clj-lc-tstrds03
[2017-10-29T10:26:58+00:00] WARN: Sentinel is clj-lc-tstrds03
[2017-10-29T10:26:59+00:00] WARN: master ip is {}
So the master_ip is empty.
Any ideea how to do this better?
Thank you!
Gabi
P.S. running everything by hand in the machine, i get the IP.