# ERROR! 'item' is undefined" with synchronize module + with items

**URL:** <https://forum.ansible.com/t/error-item-is-undefined-with-synchronize-module-with-items/20627>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [February 19, 2016, 8:49am UTC](https://forum.ansible.com/t/error-item-is-undefined-with-synchronize-module-with-items/20627 "2016-02-19T08:49:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AS1](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@AS1](https://forum.ansible.com/u/AS1)\
**Post date:** [February 19, 2016, 8:49am UTC](https://forum.ansible.com/t/error-item-is-undefined-with-synchronize-module-with-items/20627/1 "2016-02-19T08:49:34Z")

</div>

Do you guys know why ansible gives me an error ‘item’ is undefined on this specific case?

Version:  
Ansible 2.0.0.2  
Ubuntu 15.10

- name: Synchronize files  
synchronize:  
src: “{{ item.source }}”  
dest: “{{ item.dest }}”  
recursive: yes  
links: yes  
times: yes  
rsync\_opts: “–devices”  
with\_items:
- { source: project/conf/file.conf, dest: /etc/asdf/nginx.conf }
- { source: project/conf/somefolder/, dest: /etc/asdf/somefolder/ }
- { source: /conf/asdf/anotherfolder/, dest: /etc/asfd/anotherfolder/ }

Result:

TASK [mumbojumbo: Synchronize files] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/asdf/wef/main.yml:27  
fatal: [xxx.xxx.xxx.xxx]: FAILED! =\> {“failed”: true, “msg”: “ERROR! ‘item’ is undefined”}

**Second problem with the same case:**

By some reason using quotes causes an Syntax error?

- name: Synchronize files  
synchronize:  
src: “{{ item.source }}”  
dest: “{{ item.dest }}”  
recursive: yes  
links: yes  
times: yes  
rsync\_opts: “–devices”  
with\_items:
- { source: ‘project/conf/file.conf’, dest: ‘/etc/asdf/nginx.conf’ }
- { source: ‘project/conf/somefolder/’, dest: ‘/etc/asdf/somefolder/’ }
- { source: ‘/conf/asdf/anotherfolder/’, dest: ‘/etc/asfd/anotherfolder/’ }

→

ERROR! Syntax Error while loading YAML.

The error appears to have been in ‘/home/osboxes/analytics/tstdeployment/roles/orfer/tasks/main.yml’: line 36, column 86, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

with\_items:

- { source: ‘project/conf/file.conf’, dest: ‘/etc/asdf/nginx.conf’ }

^ here  
This one looks easy to fix. It seems that there is a value started  
with a quote, and the YAML parser is expecting to see the line ended  
with the same kind of quote. For instance:

when: “ok” in result.stdout

Could be written as:

when: ‘“ok” in result.stdout’

Or equivalently:

when: “‘ok’ in result.stdout”

---

<div class="post-metadata">

**Author:** ![AS1](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@AS1](https://forum.ansible.com/u/AS1)\
**Post date:** [February 19, 2016, 10:51am UTC](https://forum.ansible.com/t/error-item-is-undefined-with-synchronize-module-with-items/20627/2 "2016-02-19T10:51:57Z")

</div>

Fixed the indentation to with\_items block but still it does not work.

**Try 1**

- name: Synchronize files  
synchronize: src=“{{ item.source }}” dest=“{{ item.dest }}” recursive=yes links=yes times=yes rsync\_opts=“–devices”  
with\_items:
- { source: project/conf/file.conf, dest: '/etc/asdf/nginx.conf }
- { source: project/conf/somefolder/, dest: '/etc/asdf/somefolder/ }
- { source: /conf/asdf/anotherfolder/', dest: '/etc/asfd/anotherfolder/ }

—\>

TASK [mumbojumbo : Synchronize files] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [xxx.xxx.xxx.xxx] =\> (item={u’dest’: u’/etc/asdf/nginx.conf\xa0’, u’source’: u’project/conf/file.conf’}) =\> {“failed”: true, “item”: {“dest”: "/etc/asdf/nginx.conf ", “source”: “project/conf/file.conf”}, “module\_stderr”: “sudo: a password is required\n”, “module\_stdout”: “”, “msg”: “MODULE FAILURE”, “parsed”: false}  
failed: [xxx.xxx.xxx.xxx] =\> (item={u’dest’: u’/etc/asdf/somefolder/\xa0’, u’source’: u’project/conf/somefolder/‘}) =\> {“failed”: true, “item”: {“dest”: "/etc/asdf/somefolder/ ", “source”: “project/conf/somefolder/”}, “module\_stderr”: “sudo: a password is required\n”, “module\_stdout”: “”, “msg”: “MODULE FAILURE”, “parsed”: false}  
failed: [xxx.xxx.xxx.xxx] =\> (item={u’dest’: u’/etc/asfd/anotherfolder/\xa0’, u’source’: u’/conf/asdf/anotherfolder/'}) =\> {“failed”: true, “item”: {“dest”: "/etc/asfd/anotherfolder/ ", “source”: “/conf/asdf/anotherfolder/”}, “module\_stderr”: “sudo: a password is required\n”, “module\_stdout”: “”, “msg”: “MODULE FAILURE”, “parsed”: false}

**Try 2**

- name: Synchronize files  
synchronize:  
src: “{{ item.source }}”  
dest: “{{ item.dest }}”  
recursive: yes  
links: yes  
times: yes  
rsync\_opts: “–devices”  
with\_items:
- { source: project/conf/file.conf, dest: /etc/asdf/nginx.conf }
- { source: project/conf/somefolder/, dest: /etc/asdf/somefolder/ }
- { source: /conf/asdf/anotherfolder/, dest: /etc/asfd/anotherfolder/ }

TASK [mumbojumbo : Synchronize files] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [xxx.xxx.xxx.xxx]: FAILED! =\> {“failed”: true, “msg”: “ERROR! ‘item’ is undefined”}

**Try 3**

- name: Synchronize files  
synchronize:  
src: “{{ item.source }}”  
dest: “{{ item.dest }}”  
recursive: yes  
links: yes  
times: yes  
rsync\_opts: “–devices”  
with\_items:
- { source: ‘project/conf/file.conf’, dest: ‘/etc/asdf/nginx.conf’ }
- { source: ‘project/conf/somefolder/’, dest: ‘/etc/asdf/somefolder/’ }
- { source: ‘/conf/asdf/anotherfolder/’, dest: ‘/etc/asfd/anotherfolder/’ }

ERROR! Syntax Error while loading YAML.

The error appears to have been in ‘/home/osboxes/analytics/tstdeployment/roles/orfer/tasks/main.yml’: line 36, column 86, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

with\_items:

- { source: ‘project/conf/file.conf’, dest: ‘/etc/asdf/nginx.conf’ }  
^ here  
This one looks easy to fix. It seems that there is a value started  
with a quote, and the YAML parser is expecting to see the line ended  
with the same kind of quote. For instance:

when: “ok” in result.stdout

Could be written as:

when: ‘“ok” in result.stdout’

Or equivalently:

when: “‘ok’ in result.stdout”

**Try 4**

- name: Synchronize files  
synchronize:  
src: “{{ item.source }}”  
dest: “{{ item.dest }}”  
recursive: yes  
links: yes  
times: yes  
rsync\_opts: “–devices”  
with\_items:
- { source: “project/conf/file.conf”, dest: “/etc/asdf/nginx.conf” }
- { source: “project/conf/somefolder/”, dest: “/etc/asdf/somefolder/” }
- { source: “/conf/asdf/anotherfolder/”, dest: “/etc/asfd/anotherfolder/” }

ERROR! Syntax Error while loading YAML.

The error appears to have been in ‘/home/osboxes/analytics/tstdeployment/roles/orfer/tasks/main.yml’: line 36, column 86, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

with\_items:

- { source: ‘project/conf/file.conf’, dest: ‘/etc/asdf/nginx.conf’ }  
^ here  
This one looks easy to fix. It seems that there is a value started  
with a quote, and the YAML parser is expecting to see the line ended  
with the same kind of quote. For instance:

when: “ok” in result.stdout

Could be written as:

when: ‘“ok” in result.stdout’

Or equivalently:

when: “‘ok’ in result.stdout”

---

<div class="post-metadata">

**Author:** ![AS1](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@AS1](https://forum.ansible.com/u/AS1)\
**Post date:** [February 23, 2016, 11:06am UTC](https://forum.ansible.com/t/error-item-is-undefined-with-synchronize-module-with-items/20627/3 "2016-02-23T11:06:23Z")

</div>

Struggled with this problem for few days and finally managed to fix it.

1. Removed ansible from the machine (deleted everything)

`ansible --version ansible 2.0.1.0 (detached HEAD bec698052f) last updated 2016/02/22 11:04:54 (GMT +100) lib/ansible/modules/core: (detached HEAD 9552a22b83) last updated 2016/02/22 11:04:59 (GMT +100) lib/ansible/modules/extras: (detached HEAD 51cddf2b35) last updated 2016/02/22 11:05:05 (GMT +100) config file = configured module search path = Default w/o overrides`

1. Executed following code:

`

- name: Synchronize files  
delegate\_to: “{{ inventory\_hostname }}”  
synchronize:  
recursive: yes  
links: yes  
times: yes  
src: “{{ item.source }}”  
dest: “{{ item.dest }}”  
with\_items:
- { source: ‘{{ some\_path }}/some.git/file.txt’, dest: ‘/abc/def/file.txt’ }  
`

→ works ok

I have had multiple syntax errors in my “code” but by some reason had more problems with 2.0.0.2 and 22th Feb 2016 git version seems to work better for me.

Found out that one error that I had was one space character indentation before the block and previous block was without the indentation so that caused one error. However; there were multiple other small syntax errors.
