Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display banner message in Ansible

Tags:

ansible

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?

like image 901
GMaster Avatar asked Mar 18 '17 17:03

GMaster


People also ask

What is so fun about the default error messages in Ansible?

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.

What happens when you run an Ansible playbook?

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

How do I print uptime output to standard out in Ansible?

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.

Can I run Ansible on Ubuntu 20 04?

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.


1 Answers

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"
    ]
}
like image 105
helloV Avatar answered Sep 23 '22 06:09

helloV