如何在ansible中打印对象?

J0h*_*4lt 10 ansible ansible-playbook

我想在ansible中打印一个注册对象以帮助调试.我该怎么做?

Kas*_*yap 11

你也有to_nice_yaml,to_nice_json如果你想控制格式本身.更多细节在这里.


J0h*_*4lt 9

您需要在debug语句中使用with_dict和var =:

- tasks: 
  - name: build web node
    nova_compute:
    arguments: xyz
    register: os_web_node
  - debug: var={{ item }}
    with_dict: os_web_node
Run Code Online (Sandbox Code Playgroud)

  • 需要在使用 with_dict 的变量周围使用 jinja2 模板,否则会抛出错误“with_dict 需要一个 dict”。示例: - debug: var={{ item }} with_dict: "{{ os_web_node }}" (3认同)