# jenkins ansible template

**URL:** <https://forum.ansible.com/t/jenkins-ansible-template/26495>\
**Category:** Ansible Project\
**Created:** [January 16, 2018, 11:00pm UTC](https://forum.ansible.com/t/jenkins-ansible-template/26495 "2018-01-16T23:00:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sidh](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Sidh](https://forum.ansible.com/u/Sidh)\
**Post date:** [January 16, 2018, 11:00pm UTC](https://forum.ansible.com/t/jenkins-ansible-template/26495/1 "2018-01-16T23:00:15Z")

</div>

Hi,

i am trying to add multiple sudoers line with template.

so, i am passing sudoers=abc,def within jenkins and use -e (extended vars) while running playbook

in template:

{% for item in sudoers %}  
{{ item }} ALL=(ALL) NOPASSWD:ALL  
{% endfor %}

yml files looks like :

- name: sudoers file  
template:  
src: /templates/app.j2  
dest: /etc/sudoers.d/app  
owner: root  
group: root  
mode: 0440  
with\_items: ‘{{ sudoers }}’

Out put is :

a ALL=(ALL) NOPASSWD:ALL  
b ALL=(ALL) NOPASSWD:ALL  
c ALL=(ALL) NOPASSWD:ALL  
, ALL=(ALL) NOPASSWD:ALL  
d ALL=(ALL) NOPASSWD:ALL  
e ALL=(ALL) NOPASSWD:ALL  
f ALL=(ALL) NOPASSWD:ALL

i was expecting :  
abc (ALL) NOPASSWD:ALL  
def (ALL) NOPASSWD:ALL

any ideas ?

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [January 16, 2018, 11:15pm UTC](https://forum.ansible.com/t/jenkins-ansible-template/26495/2 "2018-01-16T23:15:30Z")

</div>

Your ‘sudoer’ is a string, you want the with\_items to iterate over a list. Try this:

with\_items: “{{ sudoers.split(‘,’) }}”

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![Sidh](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Sidh](https://forum.ansible.com/u/Sidh)\
**Post date:** [January 16, 2018, 11:32pm UTC](https://forum.ansible.com/t/jenkins-ansible-template/26495/3 "2018-01-16T23:32:37Z")

</div>

Thanks Pshem but i am still getting same result.

Regards,  
Sudhir

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [January 16, 2018, 11:48pm UTC](https://forum.ansible.com/t/jenkins-ansible-template/26495/4 "2018-01-16T23:48:53Z")

</div>

I just realised you have in fact two loops in there - one in the task (with\_items) and one in the template (for). I think the easiest way is to drop the with\_items and use the one inside the template:

{% for item in sudoers.split(‘,’ %}

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![Sidh](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Sidh](https://forum.ansible.com/u/Sidh)\
**Post date:** [January 16, 2018, 11:54pm UTC](https://forum.ansible.com/t/jenkins-ansible-template/26495/5 "2018-01-16T23:54:40Z")

</div>

Yeah, just did this and it worked :

Great. thanks.

Regards,  
Sudhir
