As I hope you can see, the idea is to use the register value from the first play to work in the second, which is aimed at another host. I get “‘import_job_count’ is undefined” because the register value doesn’t persist. Is there any way to do this?
Register variables is per host not global, so you need to specify the host you want to retrieve it from.
To do this you need to use hostvars
hostvars['Host1'].import_job_count.stdout
Yes, but a registered variable will always be defined if the task is run or skipped.
So if you have the play Host1 before this, the variable import_job_count will be defined and the when will always be true.
And a tips to improve readability, you can write your with_items like this.
Thanks for the “with_items tip. Please allow me to ask this again: the value of " import_job_count” must be 0 (zero) in order for the play to proceed. How do I do that?
I have a similar problem but the solution doesn’t seem to apply.
I have multiple plays in a single playbook, but all the plays are on localhost. A fact set in one play does not seem to be available in other plays, because the hostname is “localhost” for all of them! Is there anyway to distinguish between such plays?