Hello Guys,
Can you please help me on how can we pass the value of a variables form one playbook to another.
Hello Guys,
Can you please help me on how can we pass the value of a variables form one playbook to another.
The sort answer is you can't, what you can do is having multiple plays in _one_ playbook, a play has access to variables in previous plays.
is it possible with any other way that we can achieve it
write them into files that are loaded by other playbooks. That’s basically what inventory is, but you have all sorts of other vars files…
i have created a variable file in which i have create a variable for e.g a =10 which is working fine but i want to update the value of the variable as per the playbook (suppose playbook modifying the value a = 20) and want to use that value in another playbook(as a =20) but when i am trying to do the same variable is giving the old value(a=10) rather than the new value(a=20).
Sorry, I’m a beginner and haven’t used the relevant modules, so I can’t give specific advice.
But this page for 2.4 details a bunch of things you may find useful.
Or maybe someone with more experience and a better idea could leap in with a better answer
Regards, K.
You have 2 main scopes for variables play scope and host scope. A
variable you define in play A will not be available on play B.
You do have hostvars always available via
hostvars[<hostname>][<varname>], so even if both plays target
different hosts, you can still indirectly reference the var.
Both the files are present on a localhost… but when i am trying to reference value b = hostvars[localhost][a] into the second file into the variable b it was throwing an error “The task includes an option with an undefined variable”…