# sudoers.d file with template and validate is failing

**URL:** <https://forum.ansible.com/t/sudoers-d-file-with-template-and-validate-is-failing/25319>\
**Category:** Ansible Project\
**Created:** [August 24, 2017, 5:58am UTC](https://forum.ansible.com/t/sudoers-d-file-with-template-and-validate-is-failing/25319 "2017-08-24T05:58:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyler\_K](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@Tyler\_K](https://forum.ansible.com/u/Tyler_K)\
**Post date:** [August 24, 2017, 5:58am UTC](https://forum.ansible.com/t/sudoers-d-file-with-template-and-validate-is-failing/25319/1 "2017-08-24T05:58:03Z")

</div>

I have a task that is supposed to use a template to create a sudoers.d file and validate it. When the play runs it fails because of the validation. But when I create the file without validation and then validate the file myself it passes. In the template it uses variables to populate part of the sudoers file. I have a feeling it is related to these variables. But, when I removed the validate it populates the file correctly using those variables. I am attaching the error, task and template.

error:

`  
visudo: \>\>\> /home/vagrant/.ansible/tmp/ansible-tmp-1503552876.43-124832201376320/source: syntax error near line 1 \<\<\<

`

template:

`

```auto
dd-agent ALL=(root) NOPASSWD:{{ ddagent_sudo_commands | join(',') }}

```

`

task with variables:

`

- name: Add DataDog Agent Sudoers  
template:  
src: etc/sudoers.d/ddagent.j2  
dest: /etc/sudoers.d/ddagent  
group: root  
owner: root  
mode: ‘0440’  
validate: ‘/usr/sbin/visudo -cf %s’  
when: ddagent\_sudo\_commands | default(None) != None

`

playbook:

`

- name: Deploy DataDog Raid Checks  
hosts: myhosts  
become: yes  
vars:
- ddagent\_sudo\_commands:
- ‘/etc/dd-agent/checks.d/megarc.bin’
- ‘/usr/sbin/mpt-status’  
roles:
- common
- Datadog.datadog
- cccom-datadog-checks

`

---

<div class="post-metadata">

**Author:** ![Tyler\_K](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@Tyler\_K](https://forum.ansible.com/u/Tyler_K)\
**Post date:** [August 24, 2017, 6:33am UTC](https://forum.ansible.com/t/sudoers-d-file-with-template-and-validate-is-failing/25319/2 "2017-08-24T06:33:37Z")

</div>

Welp, I think the issue was related to my editor. I was using pycharm. It must have formatted the file somehow, cause I deleted the file then opened it in vim and pasted the same line. It worked
