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

17 views
Skip to first unread message

Jimmy Htor

unread,
Dec 27, 2018, 6:57:41 AM12/27/18
to Ansible Project
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
Message has been deleted

Matthieu Ducorps

unread,
Jan 1, 2019, 3:37:19 AM1/1/19
to Ansible Project
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

Francis Santos

unread,
Jan 3, 2019, 12:45:18 PM1/3/19
to Ansible Project
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

Hugo Gonzalez

unread,
Jan 3, 2019, 4:41:59 PM1/3/19
to ansible...@googlegroups.com

Hi Jimmy,

JSON doesn't support comments, but you can create a dummy variable called _comment and put your debugging messages there, right in the JSON. An unused variable won't mess up your inventory data.


Another option is to use the  syslog facility for whatever language you're writing the inventory script in.

In bash, it would be :

$ logger "spam and eggs happened"


Cheers,


Hugo


--

Hugo F. gonzalez

Senior Consultant

Red Hat LATAM

Reply all
Reply to author
Forward
0 new messages