Ansible: Store command’s stdout in new variable?


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.

Here are the relevant parts of the playbook:

and let’s say this is my template:

(Notice the {{ string_to_echo }})

So what I’m basically looking for is a way to store the contents of command_output.stdout (which is generated/retrieved during the first task) in a new variable string_to_echo.
That variable I’d like to use in multiple templates afterwards.

I guess I could just use {{command_output.stdout}} in my templates, but I want to get rid of that .stdout for readability.


You have to store the content as a fact:

Leave a Reply