Inside my playbook I\'d like to create a variable holding the output of an external command. Afterwards I want to make use of that variable in a couple of templates.
I'm a newbie in Ansible, but I would suggest next solution:
playbook.yml
...
vars:
command_output_full:
stdout: will be overriden below
command_output: {{ command_output_full.stdout }}
...
...
...
tasks:
- name: Create variable from command
command: "echo Hello"
register: command_output_full
- debug: msg="{{ command_output }}"
It should work (and works for me) because Ansible uses lazy evaluation. But it seems it checks validity before the launch, so I have to define command_output_full.stdout
in vars.
And, of course, if it is too many such vars in vars
section, it will look ugly.