# Struggling with complex lists and dictionaries

**URL:** <https://forum.ansible.com/t/struggling-with-complex-lists-and-dictionaries/24354>\
**Category:** Ansible Project\
**Created:** [April 28, 2017, 9:47pm UTC](https://forum.ansible.com/t/struggling-with-complex-lists-and-dictionaries/24354 "2017-04-28T21:47:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![burns498](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@burns498](https://forum.ansible.com/u/burns498)\
**Post date:** [April 28, 2017, 9:47pm UTC](https://forum.ansible.com/t/struggling-with-complex-lists-and-dictionaries/24354/1 "2017-04-28T21:47:54Z")

</div>

Hello Ansible Project - Assistance requested.

I’m attempting to create a new playbook that heavily uses loop iterations over lists and dictionaries.This is my first time using loops of any significance within Ansible, and I fear I’ve bit off more than I can chew.

**The Goal:** Create a playbook to deploy a list of application fixpacks, but first backup all of the required files of said fixpacks.

Currently I have something like the below approach:

1. User passes JSON _list_ on command line as extra-var {{ FPs }}
2. Items in JSON list are used to include\_vars
3. role vars contain a _list_ of _dictionaries_
4. Loop over the list of include\_vars, which has a list of dictionaries to backup required files.  
Sample code thus far…

**1) Command Line**

> ansible-playbook pb.yml --extra-vars ‘{ “FPs”: [‘FP1’,‘FP2’] }’

**2) Include Vars**

`

- name: Include vars for FP list  
include\_vars: “{{ item }}.yml”  
register: include\_vars\_output  
with\_items: “{{ FPs }}”

`

**3) role vars**:

`

# FP1.yml

# List of Dictionaries

backup\_files:

- src\_path: “{{ HOME }}/distribution/”  
filename: “scope.war”  
dest\_path: “{{ Backup\_dir }}/scope/”

- src\_path: “{{ HOME }}/cbs/bin/”  
filename: “PkPreProcessDOC”  
dest\_path: “{{ Backup\_dir }}/cbs/bin/”

`

`

# FP2.yml

# List of Dictionaries

backup\_files:

- src\_path: “{{ HOME }}/distribution/”  
filename: “build.xml”  
dest\_path: “{{ Backup\_dir }}/scope/”

`

**4) Backup required files before deployment**  
Disclaimer: Code breaks here since I can’t figure out how to parse out the variables I need

`

- name: Backup files  
copy:  
src: “{{ item.src\_path }}{{ item.filename }}”  
dest: “{{ item.dest\_path }}{{ item.filename }}.pre{{ item.item }}”  
remote\_src: yes  
with\_items: “{{ include\_vars\_output.results.ansible\_facts.backup\_files }}”

`

**Sample include\_vars\_output.results debug output:**

> {  
> “item”: {  
> “ansible\_facts”: {  
> “backup\_files”: [  
> {  
> “dest\_path”: “{# Backup\_dir #}/scope/”,  
> “filename”: “scope.war”,  
> “src\_path”: “{# HOME #}/distribution/”  
> }  
> ]  
> },  
> “invocation”: {  
> “module\_args”: {  
> “\_raw\_params”: “FP1.yml”  
> },  
> “module\_name”: “include\_vars”  
> },  
> “item”: “FP1”  
> }  
> }

**Error Text:**

> [DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a  
> fatal error.: ‘list object’ has no attribute ‘ansible\_facts’.  
> This feature will be removed  
> in a future release. Deprecation warnings can be disabled by setting  
> deprecation\_warnings=False in ansible.cfg.

Example above is two fixpacks with a total of 3 files to backup. I end up with a rather deep list of lists. of lists.. of dictionaries.

I’ve checked [syntax](http://docs.ansible.com/ansible/YAMLSyntax.html), [loops](http://docs.ansible.com/ansible/playbooks_loops.html), and [examples](https://www.sbarjatiya.com/notes_wiki/index.php/Working_with_lists_and_dictionary_variables_in_ansible)but can’t seem to dig myself out.  
It may well be that I am approaching this all wrong or attempting the impossible.

Thanks
