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

722 views
Skip to first unread message

AS

unread,
Feb 19, 2016, 3:49:34 AM2/19/16
to Ansible Project
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"


AS

unread,
Feb 19, 2016, 5:51:58 AM2/19/16
to Ansible Project
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/" }
  

AS

unread,
Feb 23, 2016, 6:06:23 AM2/23/16
to Ansible Project
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

2. 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.
Reply all
Reply to author
Forward
0 new messages