catch return code

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…
`

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

wow…guess i need some sleep. sorry for this.

No worries, good night and sleep tight :slight_smile:

when: executes 'before the command' but you can use
failed_when/changed_when to check the code 'after' in the same task.