help with templating

33 views
Skip to first unread message

Makimoto Marakatti

unread,
May 7, 2014, 7:39:22 AM5/7/14
to ansible...@googlegroups.com
Hi

My latest roadblock is trying to template sudoers. And I can't figure out why this won't work:

My playbook calling the role is simple enough:

---
- hosts: host1
  sudo
: True
  gather_facts
: no
  roles
:
   
- { role: myrole, sudoers: true, altsudoers: false }

And the tasks/main.yml goes like this:

---
- name: template the sudoers file
 
template: src=sudoers.j2 dest=/etc/sudoers owner=root group=root mode=0400 validate="visudo -cf %s"
 
when: sudoers

So nothing out of the ordinary. Even dull.
When it plays, this happens:

$ ansible-playbook playbook.yml  -s

PLAY
[host1] **************************************************************

TASK
: [myrole | template the sudoers file] **********************************
failed
: [host1] => {"cmd": "visudo -cf /tmp/ansible-tmp-1399451238.53-220572162134665/source", "failed": true, "item": "", "rc": 2}
msg
: [Errno 2] No such file or directory

When I go to the client machine to see the file, the whole dir "ansible-tmp-1399451238.53-220572162134665", is not there. It does not exist.

So one would think "permissions" or "sudo" issues, but this following task works with no issues whatsoever in the very same dir (/tmp):

- name: alternative copy the sudoers to /tmp
  copy
: src=sudoers dest=/tmp/sudoers
 
when: altsudoers

- name: alternative validate the /tmp copy
  shell
: "/usr/sbin/visudo -c -f /tmp/sudoers && cp /tmp/sudoers /etc/sudoers"
 
when: altsudoers

- name: alternative clean up
  shell
: rm /tmp/sudoers removes=/tmp/sudoers
 
when: altsudoers

It would seem this has nothing to do with permissions, then.
So what am I missing? in a very simple templating operation?

Thanks

Brian Coca

unread,
May 7, 2014, 8:22:43 AM5/7/14
to ansible...@googlegroups.com
add full path to visudo in validate, its failing to find it​

Makimoto Marakatti

unread,
May 7, 2014, 9:02:16 AM5/7/14
to ansible...@googlegroups.com
That was the issue indeed.

Thanks!
Reply all
Reply to author
Forward
0 new messages