大网数据广告活动
服务器运维问答

ansible print debug msg variable

· 52CE 我爱测

I try to print the previously registered mosh_version variable using the ansible debug msg command like this: - name: Print mosh version debug: msg="Mosh Version: {{ mosh_version.stdout }}" It doesn't work and prints the followin…

问题原文

原帖链接 · Zulakis · CC BY-SA 3.0

I try to print the previously registered mosh_version variable using the ansible debug msg command like this:

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

It doesn't work and prints the following error:

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

I tried

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

but this will just print "Mosh".

What's the best way to get this running?

已采纳解答

原帖链接 · Tom Aac · CC BY-SA 3.0

Try this:

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

More info in http://docs.ansible.com/YAMLSyntax.html#gotchas

Edited: Something like this works perfect for me:

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

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

http://pastie.org/private/cgeqjucn3l5kxhkkyhtpta

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-06-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。