When using group_vars : ValueError: dictionary update sequence element #0 has length 1; 2 is required

459 views
Skip to first unread message

Sean McConkey

unread,
Apr 20, 2017, 1:37:26 PM4/20/17
to Ansible Project
Hi,

I am introducing group_vars & children in my inventory into my Ansible environment as I need to update cron-tabs for different geographical regions using templates the basics of what you can see below. When I run the playbook it produces the error as seen at the bottom. A bit of research tells me that I am not the only 1 to see similar errors. Is this a bug that can be fixed with an upgrade or are there work-arounds? I've tried the vars file with different formatting to no avail.

Version Info : ansible 2.2.1.0

e.g. Template

{{ daily_min }} {{ daily_hr }} * * 0 /path/weekly.sh  > /dev/null 2>&1

{{ weekly_min }} {{ weekly_hr }} * * * /path/chk.sh  > /dev/null 2>&1


e.g. Group_var

---
- crons:
   
- { daily-min: "15", daily-hr: "01" }
   
- { weekly-min: "15", weekly-hr: "03" }




e.g. Playbook

    - name: create crontab
      tags
: cron
     
template:
        src
: templates/cron.template
        dest
: /var/spool/cron/user
        owner
: root
       
group: root
        mode
: 0644
        backup
: yes

# ansible-playbook --ask-become-pass push-crons.yml --limit hostname --check -vvv


ERROR
! Unexpected Exception: dictionary update sequence element #0 has length 1; 2 is required
the full traceback was:

Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 103, in <module>
    exit_code = cli.run()
  File "/usr/lib/python2.7/site-packages/ansible/cli/playbook.py", line 132, in run
    inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 98, in __init__
    self.parse_inventory(host_list)
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 165, in parse_inventory
    group.vars = combine_vars(group.vars, self.get_group_variables(group.name))
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 555, in get_group_variables
    self._vars_per_group[groupname] = self._get_group_variables(groupname, vault_password=vault_password)
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 573, in _get_group_variables
    vars = combine_vars(vars, self.get_group_vars(group))
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 775, in get_group_vars
    return self._get_hostgroup_vars(host=None, group=group, new_pb_basedir=new_pb_basedir, return_results=return_results)
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 839, in _get_hostgroup_vars
    host_results = self._variable_manager.add_group_vars_file(base_path, self._loader)
  File "/usr/lib/python2.7/site-packages/ansible/vars/__init__.py", line 619, in add_group_vars_file
    data = self._load_inventory_file(path, loader)
  File "/usr/lib/python2.7/site-packages/ansible/vars/__init__.py", line 577, in _load_inventory_file
    rval.update(data)
ValueError: dictionary update sequence element #0 has length 1; 2 is required

Thanks.


Brian Coca

unread,
Apr 20, 2017, 1:48:11 PM4/20/17
to Ansible Project
vars files require that the top level is a dictionary, not a list:

```
crons:
- { daily-min: "15", daily-hr: "01" }
- { weekly-min: "15", weekly-hr: "03" }
```

----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages