I'm trying to create a playbook that incorporates the following 2 commands and due to their special characters, i cant get it to work. Is there a list of special characters i need to account for in ansible using a bash command?
- name: If file exists compare new users.txt
shell: >
diff -q users.txt <(getent passwd | awk -F: '{ print $1 }') 1>/dev/null; error="$?"
getent passwd | awk -F: '{ print $1 }' > users.txt
The error is
fatal: [localhost]: FAILED! => {
"changed": true,
"cmd": "diff -q users.txt <(getent passwd | awk -F: '{ print $1}') 1>/dev/null; error=\"$?\"\n",
"delta": "0:00:00.002893",
"end": "2022-08-19 23:43:07.324939",
"invocation": {
"module_args": {
"_raw_params": "diff -q users.txt <(getent passwd | awk -F: '{ print $1}') 1>/dev/null; error=\"$?\"\n",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"msg": "non-zero return code",
"rc": 1,
"start": "2022-08-19 23:43:07.322046",
"stderr": "/bin/sh: -c: line 0: syntax error near unexpected token `('\n/bin/sh: -c: line 0: `diff -q users.txt <(getent passwd | awk -F: '{ print $1}') 1>/dev/null; error=\"$?\"'",
"stderr_lines": [
"/bin/sh: -c: line 0: syntax error near unexpected token `('",
"/bin/sh: -c: line 0: `diff -q users.txt <(getent passwd | awk -F: '{ print $1}') 1>/dev/null; error=\"$?\"'"
],
"stdout": "",
"stdout_lines": []
}