I have a bash script in Chef that fetches the time through NTP protocol from 3 instances running NTP server. The code at present is
if not node.run_list.roles.include?("ntp_server")
bash "ntpdate" do
code <<-EOH
/usr/sbin/ntpdate -s 10.204.255.15 10.204.251.41 10.204.251.21
EOH
end
end
This has been working just fine. However, I am supposed to automate the task such as if one of the instances is replaced, there is no manual intervention required to update the IP in the code above.
To achieve that, I have been successfully able to fetch the instances running the ntp_server role.
ntp_servers = search(:node, 'role:ntp_server')
Having done that, I am unable to add those IP's to the bash subroutine in Chef shown above in the code.
Can someone let me know how am I supposed to achieve that?