how to pass the value of a variable from one playbook to another.

1,185 views
Skip to first unread message

radha gupta

unread,
Apr 19, 2018, 4:12:16 AM4/19/18
to Ansible Project
Hello Guys,


Can you please help me on how can we pass the value of a variables form one playbook to another. 

Kai Stian Olstad

unread,
Apr 19, 2018, 4:34:24 AM4/19/18
to ansible...@googlegroups.com
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.


--
Kai Stian Olstad

radha gupta

unread,
Apr 19, 2018, 4:40:26 AM4/19/18
to Ansible Project
is it possible with any other way that we can achieve it

Karl Auer

unread,
Apr 19, 2018, 5:00:51 AM4/19/18
to ansible...@googlegroups.com
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...

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f4ab2ecd-e92e-4239-bfe1-57af0dda8bb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Karl Auer

Email  : ka...@2pisoftware.com
Website: 
http://2pisoftware.com

GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

radha gupta

unread,
Apr 19, 2018, 6:00:54 AM4/19/18
to Ansible Project
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). 


On Thursday, April 19, 2018 at 2:30:51 PM UTC+5:30, Karl Auer wrote:
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...
On Thu, Apr 19, 2018 at 6:40 PM, radha gupta <radha...@gmail.com> wrote:
is it possible with any other way that we can achieve it

On Thursday, April 19, 2018 at 1:42:16 PM UTC+5:30, radha gupta wrote:
Hello Guys,


Can you please help me on how can we pass the value of a variables form one playbook to another. 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Karl Auer

unread,
Apr 19, 2018, 6:13:58 AM4/19/18
to ansible...@googlegroups.com
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.


To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/da75efa6-bbdd-4aff-b44c-3d64d641df49%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Apr 19, 2018, 10:01:26 AM4/19/18
to Ansible Project
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.


--
----------
Brian Coca

radha gupta

unread,
Apr 20, 2018, 3:29:17 AM4/20/18
to Ansible Project
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"...
Reply all
Reply to author
Forward
0 new messages