I have to access ip address of a node with role pg_client
in a cookbook recipe named hc-pg
. For testing purpose I am using a single node which has both role[pg_client]
and recipe[hc-pg]
in the runlist. hc-pg
has a recipe which tries to search on a node with role pg_client
. Following is the recipe code:
ruby_block "searchnode" do
block do
pg_client_nodes = search(:node , "chef_environment:#{node.chef_environment} AND role:pg_client")
end
end
Following is the pg_client.json file
{
"name" : "pg_client",
"description" : "Client which connects to postgres server"
}
I am using test kitchen with vagrant driver and following is the .kitchen.yml
---
driver:
name: vagrant
provisioner:
name: chef_zero
platforms:
- name: precise64
driver:
box: precise64-chef
suites:
- name: default
roles_path: ../../roles
run_list:
- role[pg_client]
- recipe[hc-pg]
attributes:
postgresql:
config:
listen_addresses: "*"
I have mentioned the role before the recipe in run list. When I converge the node for the first time, search on pg_client
returns 0 node. When the same node is converged the second time, I do get the node with pg_client
role. So my assumption is that on a fresh run, the role is not applied till chef converges the node. Is this a valid assumption? How do I access the node with a role then?