yam syntax error but actually not

46 views
Skip to first unread message

Steve Kieu

unread,
Nov 22, 2014, 6:19:07 PM11/22/14
to ansible...@googlegroups.com
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

James Martin

unread,
Nov 22, 2014, 7:54:12 PM11/22/14
to ansible...@googlegroups.com
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

Steve Kieu

unread,
Nov 23, 2014, 9:22:14 PM11/23/14
to ansible...@googlegroups.com
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.





 
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


On Saturday, November 22, 2014 6:19:07 PM UTC-5, Steve Kieu wrote:
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

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/B7hzC36EqOY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9bbfe0a7-4c19-4e3a-b667-049244449f53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Kieu

Michael DeHaan

unread,
Nov 24, 2014, 5:48:51 PM11/24/14
to ansible...@googlegroups.com
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.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages