2017-03-18 24 views
6

Tôi muốn hiển thị thông báo biểu ngữ trong Ansible sau khi hoàn thành chạy một playbook, đưa ra hướng dẫn cho các bước tiếp theo. Đây là những gì tôi đã làm:Hiển thị thông điệp biểu ngữ trong 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 

Nhưng điều này mang lại cho một đầu ra xấu xí như thế này:

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 

Có hơn một cách để hiển thị bài chạy tin nhắn?

Trả lời

7

Tôi làm điều gì đó tương tự như thế này trong sách của tôi. Làm thế nào về cơ cấu lại nó một chút như thế này:

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

Một lựa chọn khác là phải vượt qua các biểu ngữ như một danh sách:

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

Cảm ơn, tôi thích tùy chọn danh sách. – GMaster

+0

Tôi đã phát triển các vai trò trong playbook của mình, khi tôi thêm 'post_install' vào trong' vai trò/myrole/vars/main.yaml' của nó không hiển thị thông báo sau khi chạy playbook của tôi. Khi tôi đặt cùng một khối với 'vars' trong' vai trò/myrole/nhiệm vụ/main.yaml' nó cho lỗi. Tôi sẽ phải thêm khối 'post_install' này ở đâu? Tôi đã cố gắng để làm google, nhưng không có may mắn được nêu ra. – Nilesh

Các vấn đề liên quan