简体   繁体   English

在 Ansible 中显示横幅消息

[英]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.我想在运行剧本完成后在 Ansible 中显示一条横幅消息,提供后续步骤的说明。 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:但这给出了一个丑陋的 output,如下所示:

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 有一个Slack模块: 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 .解决方案是使用暂停模块,如另一个问题的答案中所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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