yam syntax error but actually not

Hi all,

ansible complian about these

  • name: allow group wheel to run sudo with password
    shell: “perl -i.bak -pe ‘s|^# %wheel[\s\t]+ALL=(ALL)[\s\t]+NOPASSWD|%wheel ALL=(ALL) NOPASSWD|g’ /etc/sudoers creates=/etc/sudoers.bak”

yaml lint syntax check go green :slight_smile:

ansible says:

ERROR: Syntax Error while loading YAML script, /etc/ansible/localhost/roles/base/tasks/05-usersetup.yml
Note: The error may actually appear before this position: line 11, column 34

  • name: allow group wheel to run sudo with password
    shell: “perl -i.bak -pe ‘s|^# %wheel[\s\t]+ALL=(ALL)[\s\t]+NOPASSWD|%wheel ALL=(ALL) NOPASSWD|g’ /etc/sudoers creates=/etc/sudoers.bak”

I think it mis understand some characters there but not sure what. Any idea?

Kind regards

Using the shell module to call perl to replace text in a file is jumping through a lot of hoops. Ansible aims for simple. I’d recommend using the template module (http://docs.ansible.com/template_module.html) and template out the whole sudoers file. If you must replace text, use the replace module: http://docs.ansible.com/replace_module.html. In either case I’d recommend you use the “validate” option, so you can ensure the sudoers file has the proper syntax and you don’t lock yourself out of the box.

  • James

Using the shell module to call perl to replace text in a file is jumping
through a lot of hoops. Ansible aims for simple. I'd recommend using the
template module (http://docs.ansible.com/template_module.html) and
template out the whole sudoers file. If you must

I already switch to use the template: module sfor it, just see it is
strange.

It should work but not work as expected. I hope we found some bug somewhere
and clean it up.

Quoting issues can be fun.

I’m a bit too low on caffeine to find it at the moment, but you could also consider the script module to make it easier.

I like the more native module approach for sure though, which makes things much more readable.