# yam syntax error but actually not

**URL:** <https://forum.ansible.com/t/yam-syntax-error-but-actually-not/16854>\
**Category:** Ansible Project\
**Tags:** ansible-lint\
**Created:** [November 22, 2014, 11:19pm UTC](https://forum.ansible.com/t/yam-syntax-error-but-actually-not/16854 "2014-11-22T23:19:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Kieu](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Steve\_Kieu](https://forum.ansible.com/u/Steve_Kieu)\
**Post date:** [November 22, 2014, 11:19pm UTC](https://forum.ansible.com/t/yam-syntax-error-but-actually-not/16854/1 "2014-11-22T23:19:07Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![James\_Martin1](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@James\_Martin1](https://forum.ansible.com/u/James_Martin1)\
**Post date:** [November 23, 2014, 12:54am UTC](https://forum.ansible.com/t/yam-syntax-error-but-actually-not/16854/2 "2014-11-23T00:54:12Z")

</div>

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](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](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

---

<div class="post-metadata">

**Author:** ![Steve\_Kieu](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Steve\_Kieu](https://forum.ansible.com/u/Steve_Kieu)\
**Post date:** [November 24, 2014, 2:22am UTC](https://forum.ansible.com/t/yam-syntax-error-but-actually-not/16854/3 "2014-11-24T02:22:11Z")

</div>

> 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](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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [November 24, 2014, 10:48pm UTC](https://forum.ansible.com/t/yam-syntax-error-but-actually-not/16854/4 "2014-11-24T22:48:47Z")

</div>

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.
