Is there a way to access a play's vars section?

29 views
Skip to first unread message

Nick Kakouros

unread,
Nov 9, 2018, 6:59:17 PM11/9/18
to Ansible Project
Given a play, I would like to reference somehow its vars section. I would like to achieve any of the two:

- The next play to have access to the vars of the previous play like "{{ prev_play_vars }}"
- The vars section of each play to be available to the rest of the plays via sth like "{{play_name_here_vars}}"

I tried messing around with a custom callback plugin but that didn't get me anywhere.

How could I achieve sth like that?

Brian Coca

unread,
Nov 9, 2018, 8:01:09 PM11/9/18
to ansible...@googlegroups.com
You cannot, play vars are only in scope for that play. The only vars
in a playbook you can reference across all plays are host vars.




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

Nick Kakouros

unread,
Nov 10, 2018, 8:50:05 AM11/10/18
to Ansible Project
Thanks. In that case, could I add a task to a play programmatically? I have around 20 plays and I try to have the vars section of each play to be saved locally to a yaml file. Right now, at the end of each play, I use a 'copy' tasks that reads the vars via a yaml alias. I would like to not repeat myself. I tried to place this task in a different play that is run after each one of the above plays , but ansible complains about an undefined alias. Do you see any way to not have to repeat the task in every play?

Nick Kakouros

unread,
Nov 10, 2018, 8:56:45 AM11/10/18
to Ansible Project
I forgot to mention that `import_tasks` or `include_tasks` also results in the undefined alias error.

Brian Coca

unread,
Nov 12, 2018, 9:26:14 AM11/12/18
to ansible...@googlegroups.com
To save vars to a yaml file i would just use a template task, unsure
what you are doing or why, but this seems wrong to me.

On the import_tasks, include_tasks .. no clue what 'undefined alias'
is nor can i reproduce it, you need to give a full error with -vvv
(which will include traceback)



--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages