Hi,
Yes but how can we test the result?
There is no common field for the OK result and the NOT OK result.
As for example, status or exists or true, etc.
For an existing user:
TASK [debug msg={{ ww }}] ************************************************************************************
ok: [node1] => {
"msg": {
"ansible_facts": {
"getent_passwd": {
"devops": [
"x",
"600",
"600",
"",
"/home/devops",
"/bin/bash"
]
}
},
"changed": false
}
}
For a not existing user :
TASK [debug msg={{ ww }}] ************************************************************************************
ok: [node1] => {
"msg": {
"changed": false,
"failed": true,
"msg": "One or more supplied key could not be found in the database."
}
}
when you make the conditional like for example:
- fail: msg="user xxxx doesn't exists"
when: ww.failed
But when the user exists , it also reports an error:
fatal: [node1]: FAILED! => {"failed": true, "msg": "The conditional check 'ww.failed' failed. The error was: error while evaluating conditional (ww.failed): 'dict object' has no attribute 'failed'\n\nThe error appears to have been in '/home/ansible/testeuser.yml': line 10, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n - debug: msg={{ getent_passwd }}\n - fail: msg=\"tasks5 fail in server {{ inventory_hostname }}.\"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n"}