title: Unable to search on node's role in chef cookbook recipe
body: <p>I have to access ip address of a node with role <code>pg_client</code> in a cookbook recipe named <code>hc-pg</code>. For testing purpose I am using a single node which has both <code>role[pg_client]</code> and <code>recipe[hc-pg]</code> in the runlist. <code>hc-pg</code> has a recipe which tries to search on a node with role <code>pg_client</code>. Following is the recipe code:</p>
  
  <pre><code>ruby_block "searchnode" do
    block do
     pg_client_nodes = search(:node , "chef_environment:#{node.chef_environment} AND role:pg_client")
    end
  end
  </code></pre>
  
  <p>Following is the pg_client.json file</p>
  
  <pre><code>{
  "name" : "pg_client",
  "description" : "Client which connects to postgres server"
  }
  </code></pre>
  
  <p>I am using test kitchen with vagrant driver and following is the .kitchen.yml</p>
  
  <pre><code>---
  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: "*"
  </code></pre>
  
  <p>I have mentioned the role before the recipe in run list. When I converge the node for the first time, search on <code>pg_client</code> returns 0 node. When the same node is converged the second time, I do get the node with <code>pg_client</code> 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?</p>