First of all:
You should not use shell
with sed
in ansible, but the replace module.
E.g.:
- name: Allow sudo without password
ansible.builtin.replace:
path: /etc/sudoers
regexp: '# %wheel\tALL=\(ALL\)\tNOPASSWD: ALL'
replace: '%wheel ALL=(ALL) NOPASSWD: ALL'
Check out the python doc on how to write a correct regex, espc. for tabs (\t
) and brackets.
Check out this question about how to manage sudoers as well.
Second:
Your code is not working because you do not quote your string correctly.
This should work (kudos to Zeitonautor):
shell: "sed -i -e \"s/# %wheel\\tALL=(ALL)\\tNOPASSWD: ALL/%wheel\\tALL=(ALL)\\tNOPASSWD: ALL/g\" /etc/sudoers"
Also check this post about using \t
with sed
. Using \t
will not work with every version of sed
.
Again: Do NOT use this! Use the replace module instead!