【问题标题】:How do I pretty print an object in ansible?如何在ansible中漂亮地打印一个对象?
【发布时间】:2015-04-20 10:37:03
【问题描述】:

我想在 ansible 中漂亮地打印一个已注册的对象以帮助调试。我该怎么做?

【问题讨论】:

    标签: ansible ansible-playbook


    【解决方案1】:

    如果您想控制格式本身,您还可以使用to_nice_yaml and to_nice_json。更多详情here.

    【讨论】:

      【解决方案2】:

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

      - tasks: 
        - name: build web node
          nova_compute:
          arguments: xyz
          register: os_web_node
        - debug: var={{ item }}
          with_dict: os_web_node
      

      【讨论】:

      • 需要在使用 with_dict 的变量周围使用 jinja2 模板,否则会抛出错误“with_dict 需要一个字典”。示例:- 调试:var={{ item }} with_dict: "{{ os_web_node }}"
      猜你喜欢
      • 2021-01-31
      • 2011-11-02
      • 2021-04-13
      • 2017-12-15
      • 1970-01-01
      • 2017-07-28
      • 2016-04-26
      • 2015-01-22
      • 1970-01-01
      相关资源
      最近更新 更多