debugging

2017-08-16

dump and stop loop

A simple dump some state/expression and stop the play duo, inserted where you need more info / just before something broke helps

---
- ....
- debug: var=<expression>
- meta: end_play

If you want to stop the execution of the whole playbook break it with fail

---
- ....
- debug: var=<expression>
- fail: msg=debug

stash-a-variable, hydrate-a-variable, hack-a-template loop

So when dealing with templates or really old, smelly and slow servers (aix/websphere anyone?) it is sometimes is a great idea to stop wasting time and hack locally

If you insert this bit just before the shit hits the fan in your role/playbook. so you can save the state, and transfer it locally

(also an idea is to --limit-hosts to the one server that is giving you the proverbial middle finger)

---
- < stuff that makes variable avar... >
- copy: content='{{avar|to_nice_json}}' dest='/tmp/thatavar.json'
- fetch: src=/tmp/thatavar.json flat=yes dest=./debug/
- meta: end_play

then in debug.yaml, hydrate it and template locally until it makes you smile

---
- hosts: localhost
  gather_facts: false
  connection: local
  tasks:
    - include_vars: file='./debug/thatavar.json' name=avar
    - template: src=foo.j2 dest=./debug/foo