Inventory scripts: How to add debug info when run via Ansible?

Hey,

The way I see it you either output to STDOUT, which would make debug output part of the inventory data, thus corrupt it. Or you output to STDERR and Ansible will treat is as actual errors (and show it using red color).

Is there another way to cleanly provide debug info during an Ansible run besides writing to a file?

Thx

Hello Jimmy,

Not sure if it’s what you are looking for, when you run a playbook you can use the debugger for the whole playbook or each task.

You can also use the register variable to do what every you want with what is Ansible-playbook run feedback

hope that help.

Matth

Is this what you are looking for?

tasks:

  • name: enabling consul
    service: name=consul enabled=yes state=started
    when:

  • service: name=consul state=stopped
    register: results ### stores output on a variable
    ignore_errors: yes

  • name: show results of disabling consul

debug: msg={{ results }} ### shows that output when ansible is played

  • name: logging the results
    shell: echo {{ results }} >> /var/log/fixing ### saves that output in a log

Hi Jimmy,