handling stderr

12 views
Skip to first unread message

Abhijit Chakraborty

unread,
Oct 12, 2017, 4:17:07 AM10/12/17
to ansible...@googlegroups.com
I have a playbook with the following contents

---
- hosts: all


  handlers:
  - name: user-create
    user: name=oracle state=present

  tasks:
  - name: "check user"
    command: /usr/bin/id oracle
    register: output
    notify: user-create
    when: "output.stderr not in ['succeed1', 'succeed2']"


whenver i run this playbook, encountering the following error -->

"failed": true,
    "msg": "The conditional check 'output.stderr not in ['succeed1', 'succeed2']' failed. The error was: error while evaluating conditional (output.stderr not in ['succeed1', 'succeed2']): 'output' is undefined\n\nThe error appears to have been in '/user-check.yml': line 10, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  tasks:\n  - name: \"check user\"\n    ^ here\n"


ANy help will be appreciated....

Kai Stian Olstad

unread,
Oct 12, 2017, 5:24:11 AM10/12/17
to ansible...@googlegroups.com
When: is executed first and at this time output is not populated since
command has not run yet.

You need to split it in two tasks, one that check and one that create
with the result that you don't need the handler.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages