18

I want to pretty print a registered object in ansible to help with debugging. How do I do it?

J0hnG4lt
  • 4,337
  • 5
  • 24
  • 40

2 Answers2

21

You also have to_nice_yaml and to_nice_json if you want to control the format itself. More details here.

4wk_
  • 2,458
  • 3
  • 34
  • 46
Kashyap
  • 15,354
  • 13
  • 64
  • 103
13

You need to use with_dict and var= in your debug statement:

- tasks: 
  - name: build web node
    nova_compute:
    arguments: xyz
    register: os_web_node
  - debug: var={{ item }}
    with_dict: os_web_node
J0hnG4lt
  • 4,337
  • 5
  • 24
  • 40
  • 4
    Need to use jinja2 template around variable used with_dict otherwise it throws error "with_dict expects a dict". example: - debug: var={{ item }} with_dict: "{{ os_web_node }}" – Rayon Aug 29 '20 at 18:03