Variables between playbooks

35 views
Skip to first unread message

marta.a...@gmail.com

unread,
Aug 9, 2017, 4:56:58 PM8/9/17
to Ansible Project
Hi!
I have some problem and I can't figure out the answear to it. I'm relatively new to Ansible so I'm still learning. I have to separate playbooks and I want to set a variable value in one, and use it in the other. So for example in playbook 1 I want to start ec2 instance and I want to safe its instance_id and in the next playbook run some time after that first I want to delete this instance so I want to get the instance_id value from the variable. Is this possible, and if so how? If someone knows the answear please provide some simple example, because I have found some ideas, but nothing seems to work. And if the first problem could be solved, would it be possible to save this variable in the first playbook with parameterized variable name?
Marta

Kai Stian Olstad

unread,
Aug 10, 2017, 1:35:04 PM8/10/17
to ansible...@googlegroups.com
It's not possible to share variables between playbooks, you can share
between play in the same playbook.

What you could do is store the values in a file that you read in
playbook number two.

--
Kai Stian Olstad

Pa S

unread,
Aug 10, 2017, 2:22:26 PM8/10/17
to Ansible Project, ansible-pr...@olstad.com
Well, aside from a thread on vars_files I just posted, you can use facts that seem to span imports of playbooks.  see the set_facts documentation.

You can also set variables in inventory files

marta.a...@gmail.com

unread,
Aug 11, 2017, 11:22:49 AM8/11/17
to Ansible Project, ansible-pr...@olstad.com
Thanks I guess I will put it into a new file.
Reply all
Reply to author
Forward
0 new messages