简体   繁体   中英

Display banner message in 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?

I do something similar to this in my playbooks. How about restructuring it a bit like this:

  vars:
    post_install: |
      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.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"
    ]
}

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM