How to check Task Completion on other node

i am automating a master and slave nodes. a task on slave node should be executed ONLY_IF a task of master node has been completed. I am not able to find a way to check task completion on other node.

Can anyone help on that.

Well, I am not sure what exactly you mean but there is a functionality that might just solve your problem:
Search allows you to find our on which nodes a certain attribute is set. So you could set some attribute on the master node once the “task” is completed on on the slave node you can then check if this attribute is set already.

yes but i am not able to achieve this.
i am trying to set a node attribute on master but new attributes values is only for current chef client run.

what i have done is:

  1. defined a attribute in attribute.rb file
  2. modified it on master after completing the task
  3. tried to acces that attribute on slave node but on slave attribures is showing same values that I have set in attribute file
    not sure what I am missing

How do you set the attribute? Could you post the code that does so? Did you check the attribute on your chef server? Are they really set to the default in your attribute file?

thanks for quick response. here are the details

default[‘bpm’][‘ps’][‘dmgr_ready’] = ‘false’ // this is how I set in attribute file

node.default[‘bpm’][‘ps’][‘dmgr_ready’] = [‘true’] // this is how I am modifying in on master

puts node[‘bpm’][‘ps’][‘dmgr_ready’] //this is how I am checking on slave node

So, there are several things here:

1: If you set an attribute in a recipe it is safer to set the normal or override precedence rather than the default again.
2: For checking on the slave node you do not use search as I suggested. Search allows you to search on the chef server which means you can check attributes on other nodes. The way you do it, you just access a local attribute on your own node.

can you please share some example to seach an attribute for a master node on chef server. Please

The official documentation about how to do so is quite extensive and has plenty of examples. Please read this one first and if there are still problems you can ask again here.

I am using below way to search. I am using test kitchen not chef server. this serch should be working for test kichen as well right ? (chef zero in my case)

puts "i am checking dmgr ready flag now…"
puts search(:node, “dmgr_ready:true”)

You can use search in Kitchen with chef-zero but you do have provide “fake” test data that should be searched through. For that you have to

  1. Set the nodes_path in your .kitchen.yml (check kitchen diagnose for which section it should be in) to something like test/fixtures/nodes
  2. Put faked nodes in the test/fixtures/nodes. Something like:
  "name": "",
  "chef_environment": "staging",
  "run_list": [],
  "normal": {
    "tags": [],
    "bpm": {
      "ps": {
        "dmgr_ready": true

With this the search should work and return valid values.

Thank you so much joerg.herzinger

I have not tested your last suggested code but yesterday I found a solution of this. “updating an attribute on one node and then searching that attribute from other node” was not working with test kitchen. when I tested same code in chef server it worked like a charm. :slight_smile:
What I concluded yesterday that feature is not supported in Chef Zero and it is only supported in Chef Server.

Now i have one more question. I have read the complete documentation regarding search we can only search node, environment and few more things but I could not find how to search value of an attribute. i have able to search a node where dmgr_ready = true (search result is a node) but i need to find a way to get values of this parameter (search result should be ‘true’ or ‘false’ i.e the value of the attribute)

Thanks again for your great and quick support and help

There are plenty of examples in the docs about how to search for a specific Attribute value. Please read the docs again…

Replying to my own post.

that is resolved :slight_smile: here is the code

result = search(:node, “hostname:#{node[‘dmgr_host’]}”)
puts "showing value of result"
puts result

puts "showing dmgr_ready flag value of resultant node"
puts result[0][:dmgr_ready]

chef isnt really an orchestration system, you’re better off using consul or etcd to provide semaphores.