Deployment

ansible 列印調試消息變數

  • July 27, 2021

我嘗試mosh_version使用 ansibledebug msg命令列印以前註冊的變數,如下所示:

- name: Print mosh version
 debug: msg="Mosh Version: {{ mosh_version.stdout }}"

它不起作用並列印以下錯誤:

Note: The error may actually appear before this position: line 55, column 27

- name: Print mosh version
 debug: msg="Mosh Version: {{ mosh_version.stdout }}"
                         ^
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance:

   with_items:
     - {{ foo }}

Should be written as:

   with_items:
     - "{{ foo }}"

我試過

- name: Print mosh version
 debug: msg=Mosh Version: "{{ mosh_version.stdout }}"

但這只會列印“Mosh”。

讓它執行的最佳方法是什麼?

試試這個:

- name: Print mosh version
 debug: "msg=Mosh Version: '{{ mosh_version.stdout }}'"

http://docs.ansible.com/YAMLSyntax.html#gotchas中的更多資訊

編輯:這樣的東西對我來說很完美:

- name: Check Ansible version
 command: ansible --version
 register: ansibleVersion

- name: Print version
 debug:
   msg: "Ansible Version: {{ ansibleVersion.stdout }}"

http://pastie.org/private/cgeqjucn3l5kxhkkyhtpta

最簡單的答案

- debug: var=mosh_version.stdout

引用自:https://serverfault.com/questions/695786