【问题标题】:Display banner message in Ansible在 Ansible 中显示横幅消息
【发布时间】:2017-08-10 04:25:02
【问题描述】:

我想在完成运行 playbook 后在 Ansible 中显示一条横幅消息,为后续步骤提供说明。这就是我所做的:

- 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

但这会产生如下丑陋的输出:

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   

有没有更好的方法来显示运行后消息?

【问题讨论】:

    标签: ansible


    【解决方案1】:

    我在我的剧本中做了类似的事情。像这样重组它怎么样:

      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') }}
    

    输出

    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",
            ""
        ]
    }
    

    另一种选择是将横幅作为列表传递:

      - 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'
    

    输出

    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"
        ]
    }
    

    【讨论】:

    • 谢谢,我喜欢列表选项。
    • 我在我的剧本中开发了角色,当我在我的 roles/myrole/vars/main.yaml 中添加 post_install 时,它在运行我的剧本后没有显示消息。当我将与vars 相同的块放入roles/myrole/tasks/main.yaml 时,它会出错。我应该在哪里添加这个post_install 块?我试着做谷歌,但还没有运气。
    【解决方案2】:

    可能不完全是您(和我)在哪里寻找的内容,但如果您想通知重要的事情并且不希望将其隐藏在您的剧本运行中。有一个 Slack 模块:https://docs.ansible.com/ansible/latest/modules/slack_module.html

    【讨论】:

      【解决方案3】:

      这里的其他答案对我不起作用,因为所有行都连接在一起(无论我尝试了什么),这是不可读的。

      解决方案是使用 Pause 模块,如 an answer to another question 中所述。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-06
        • 1970-01-01
        • 1970-01-01
        • 2012-05-23
        • 2023-04-08
        • 2016-03-29
        • 1970-01-01
        相关资源
        最近更新 更多