I want to display a banner message in Ansible after completion of running a playbook, giving instructions for next steps. This is what i have done:
- name: display post install message
debug:
msg: |
Things left to do:
- enable dash to dock gnome plugin in gnome tweal tool
- install SpaceVim plugins: vim "+call dein#install()" +qa
- git clone the dotfiles repo
But this gives an ugly output like this:
TASK [display post install message] ********************************************
ok: [localhost] => {
"msg": "Things left to do:\n- enable dash to dock gnome plugin in gnome tweal tool\n- install SpaceVim plugins: vim \"+call dein#install()\" +qa\n- git clone the dotfiles repo\n"
}
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
Is there a better a way to display post run message?
What is so fun in displaying the built-in default error messages like “the command is wrong” or “the variable is undefined”. Most of the time the ansible returned error messages would not justify their own purpose of conveying the message on what went wrong as it would be too vague.
Ordinarily, when you run an Ansible playbook, you get execution details printed on the terminal. These include the name of the play and task and a play recap indicating if the playbook has made any changes on the managed host or remote system
We created a playbook file called check_uptime.yml, as shown. When executed, the uptime details are printed to the terminal as shown. This guide demonstrates how you can print the command’s output to standard out in Ansible. This was enlightening, and that you can now print the output of your command to std out.
In this guide, we are running Ubuntu 20.04 in which Ansible installed. Check out our guide on how to install Ansible on Ubuntu 20.04. Let take a simple playbook file that lists the home directory of the managed host or remote host. The playbook will run just fine; however, the output will not be displayed on the terminal.
I do something similar to this in my playbooks. How about restructuring it a bit like this:
vars:
post_install_message: |
Things left to do:
- enable dash to dock gnome plugin in gnome tweal tool
- install SpaceVim plugins: vim "+call dein#install()" +qa
- git clone the dotfiles repo
tasks:
- name: display post install message
debug: msg={{ post_install_message.split('\n') }}
Output
TASK [display post install message] ********************************************
ok: [localhost] => {
"msg": [
"Things left to do:",
" - enable dash to dock gnome plugin in gnome tweal tool",
" - install SpaceVim plugins: vim \"+call dein#install()\" +qa",
" - git clone the dotfiles repo",
""
]
}
Another option is to pass the banner as a list:
- name: display post install message
debug:
msg:
- 'Things left to do:'
- '- enable dash to dock gnome plugin in gnome tweal tool'
- '- install SpaceVim plugins: vim "+call dein#install()" +qa'
- '- git clone the dotfiles repo'
Output
TASK [display post install message] ********************************************
ok: [localhost] => {
"msg": [
"Things left to do:",
"- enable dash to dock gnome plugin in gnome tweal tool",
"- install SpaceVim plugins: vim \"+call dein#install()\" +qa",
"- git clone the dotfiles repo"
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With