The question "How do I set register a variable to persist between plays in Ansible?", is in the top of the frequent questions of ansible. It has attracted a lot of views and score, so it is a pretty well established one. I, myself, point or duplicate vote to it, from time to time, as variants of it are coming back.
This said, the code in the question itself has a lot of information and code unrelated to the question itself, although the question title pretty well sums up what the OP is trying to achieve.
The answerers actually didn't even care to take those extraneous information and did build up on an implicit MRE.
So, should I drastically edit the question in order to match the minimal criteria of the MRE?
The question matching an MRE should be in the line of what the first answerer propose as an example:
I have an Ansible playbook, where I would to access a variable I register on one machine to be available on another.
Given the playbook:
- hosts: localhost tasks: - command: echo "this is a test" register: foo - hosts: main tasks: - debug: msg: "{{ foo }}"
It gives me the error:
The task includes an option with an undefined variable. The error was: 'foo' is undefined
How can I access
foo
, registered onlocalhost
frommain
?