ansible 打印调试 msg 变量

Zul*_*kis 26 deployment ansible

我尝试mosh_version使用 ansibledebug msg命令打印先前注册的变量,如下所示:

- name: Print mosh version
  debug: msg="Mosh Version: {{ mosh_version.stdout }}"
Run Code Online (Sandbox Code Playgroud)

它不起作用并打印以下错误:

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 }}"
Run Code Online (Sandbox Code Playgroud)

我试过

- name: Print mosh version
  debug: msg=Mosh Version: "{{ mosh_version.stdout }}"
Run Code Online (Sandbox Code Playgroud)

但这只会打印“Mosh”。

让它运行的最佳方法是什么?

Tom*_*Aac 39

尝试这个:

- name: Print mosh version
  debug: "msg=Mosh Version: '{{ mosh_version.stdout }}'"
Run Code Online (Sandbox Code Playgroud)

更多信息在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 }}"
Run Code Online (Sandbox Code Playgroud)

http://pastie.org/private/cgeqjucn3l5kxhkkyhtpta


xdd*_*dsg 9

最简单的答案

- debug: var=mosh_version.stdout
Run Code Online (Sandbox Code Playgroud)