# ansible error with loops (with\_items)

**URL:** <https://forum.ansible.com/t/ansible-error-with-loops-with-items/27548>\
**Category:** Ansible Project\
**Created:** [May 16, 2018, 8:06pm UTC](https://forum.ansible.com/t/ansible-error-with-loops-with-items/27548 "2018-05-16T20:06:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeyyu2003](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@jeyyu2003](https://forum.ansible.com/u/jeyyu2003)\
**Post date:** [May 16, 2018, 8:06pm UTC](https://forum.ansible.com/t/ansible-error-with-loops-with-items/27548/1 "2018-05-16T20:06:06Z")

</div>

Hi, I am trying to use Ansible to reference a file to populate variables onto my mail playbook and having issues. Inline and using Jinja templates work but not with this specific configuration.

Here’s my main loop3.yml file

# Add Servers

- name: Add Server Objects from a loop  
hosts: dev\_servers  
gather\_facts: false  
vars\_files:
- server\_vars2.yml  
tasks:
- name: Create Server “{{ item.svrname }}”  
delegate\_to: localhost  
server:  
name: “{{ item.svrname }}”  
ipaddress: “{{ item.svrip }}”  
state: present  
comment: Apache Server “{{ item.svrname }}” with IP “{{ item.svrip }}”

with\_items: “{ { serverlist } }”

Here’s the file: server\_vars2.yml

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 16, 2018, 8:22pm UTC](https://forum.ansible.com/t/ansible-error-with-loops-with-items/27548/2 "2018-05-16T20:22:39Z")

</div>

What sticks out as a sore thumb is the last line, there should not be any space between {{ and }}.

And for the record, you should be consistent with your indentation, YAML only support spaces and you should the same amount of spaces for the indentation.  
After the vars\_files: you use 2 spaces, but after the tasks: you use 4 spaces.

This does not create a problem for you in this example, but for the future it is a bad idea to not keep the indentation uniform.

---

<div class="post-metadata">

**Author:** ![jeyyu2003](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@jeyyu2003](https://forum.ansible.com/u/jeyyu2003)\
**Post date:** [May 17, 2018, 3:12am UTC](https://forum.ansible.com/t/ansible-error-with-loops-with-items/27548/3 "2018-05-17T03:12:19Z")

</div>

Kai,  
Thanks. Noted on the indentation. I was able to resolve this issue by using a different editor and manually updating all the quotes. It was able to execute successfully after that. - J.
