catch return code

16 views
Skip to first unread message

christia...@itsv.at

unread,
Sep 19, 2018, 6:16:39 AM9/19/18
to Ansible Project

how to i check the return code of a shell command correctly? see error below. looks like a chicken/egg situation to me...create_oml_users should be registerd if rc is 0...any ideas?


- shell: lsuser -R files lsam 2>/dev/null
 
register: create_oml_users
 
when: create_oml_users.rc == 0
  ignore_errors
: true

fatal: [AIXWUKIT]: FAILED! => {}

MSG
:

The conditional check 'create_oml_users.rc == 0' failed. The error was: error while evaluating conditional (create_oml_users.rc == 0): 'create_oml_users' is undefined

The error appears to have been in '/etc/ansible/aix/roles/manage_ldap_users/tasks/main.yml': line 13, column 3, but may
be elsewhere
in the file depending on the exact syntax problem.

The offending line appears to be:


- shell: lsuser -R files lsam 2>/dev/null
 
^ here


...ignoring
Enter code here...




Kai Stian Olstad

unread,
Sep 19, 2018, 7:02:24 AM9/19/18
to ansible...@googlegroups.com
On 19.09.2018 12:16, christia...@itsv.at wrote:
> how to i check the return code of a shell command correctly? see error
> below. looks like a chicken/egg situation to me...create_oml_users
> should
> be registerd if rc is 0...any ideas?
>
>
> - shell: lsuser -R files lsam 2>/dev/null
> register: create_oml_users
> when: create_oml_users.rc == 0
> ignore_errors: true
>
> fatal: [AIXWUKIT]: FAILED! => {}

You must do that in the next task, not in the task itself.

--
Kai Stian Olstad

christia...@itsv.at

unread,
Sep 19, 2018, 7:37:04 AM9/19/18
to Ansible Project
wow....guess i need some sleep. sorry for this.

Kai Stian Olstad

unread,
Sep 19, 2018, 9:09:42 AM9/19/18
to ansible...@googlegroups.com
On 19.09.2018 13:37, christia...@itsv.at wrote:
> wow....guess i need some sleep. sorry for this.

No worries, good night and sleep tight :-)

--
Kai Stian Olstad

Brian Coca

unread,
Sep 19, 2018, 9:16:38 AM9/19/18
to Ansible Project
when: executes 'before the command' but you can use
failed_when/changed_when to check the code 'after' in the same task.




--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages