Displaying output of a remote command with Ansible

Question:

In an Ansible role I generate the user’s SSH key. After that I want to print it to the screen and pause so the user can copy and paste it somewhere else. So far I have something like this:

The ‘Show SSH public key’ task completes but doesn’t show the output.

There may be a better way of going about this. I don’t really like the fact that it will always show a ‘changed’ status. I did find this pull request for ansible – https://github.com/ansible/ansible/pull/2673 – but not sure if I can use it without writing my own module.

Answer:

I’m not sure about the syntax of your specific commands (e.g., vagrant, etc), but in general…

Just register Ansible’s (not-normally-shown) JSON output to a variable, then display each variable’s stdout_lines attribute:

Leave a Reply