17

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?

GMaster
  • 1,431
  • 1
  • 16
  • 27

3 Answers3

24

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"
    ]
}
jboot
  • 23
  • 4
helloV
  • 50,176
  • 7
  • 137
  • 145
  • Thanks, I like the list option. – GMaster Mar 19 '17 at 03:12
  • I developed roles in my playbook, when I add `post_install` in my `roles/myrole/vars/main.yaml` its not displaying message after running my playbook. When I put same block with `vars` in `roles/myrole/tasks/main.yaml` it gives error. Where should I have to add this `post_install` block? I tried to do google, but no luck yet. – Nilesh Jan 22 '18 at 15:25
0

maybe not exactly what you (and me) where looking for, but if you want to notify about important things and don't want have it buried in your playbook runs. There is a Slack module: https://docs.ansible.com/ansible/latest/modules/slack_module.html

Markus
  • 1,887
  • 18
  • 23
0

The other answers here didn't work for me because all lines got concatenated together (no matter what I tried), which wasn't readable.

The solution was to use the Pause module, as discussed in an answer to another question.

colan
  • 2,818
  • 2
  • 20
  • 17