# workaround for using a variable list of vars with include

**URL:** <https://forum.ansible.com/t/workaround-for-using-a-variable-list-of-vars-with-include/19343>\
**Category:** Ansible Developer\
**Created:** [September 23, 2015, 3:42pm UTC](https://forum.ansible.com/t/workaround-for-using-a-variable-list-of-vars-with-include/19343 "2015-09-23T15:42:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javeria\_Khan](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Javeria\_Khan](https://forum.ansible.com/u/Javeria_Khan)\
**Post date:** [September 23, 2015, 3:42pm UTC](https://forum.ansible.com/t/workaround-for-using-a-variable-list-of-vars-with-include/19343/1 "2015-09-23T15:42:50Z")

</div>

Hi everyone,

I need to include a playbook which essentially contains a set of initialisation tasks for any set of variables passed to it. Like so:

1. 
  - include: upstart\_common\_init.yml

2. vars:

3. program\_name: “{{ item.service\_name }}”

4. program\_config\_options: “–config-file /etc/xyz/{{ item.service\_conf }}”

5. system\_user: “{{ system\_user\_name }}”

6. system\_group: “{{ system\_group\_name }}”

7. service\_home: “{{ system\_home\_folder }}”

8. with\_items: some\_services

9. when: \>

10. inventory\_hostname in groups[item.service\_group] and

11. item.service\_en == true

12. tags:

13. 
  - upstart-init

Where the **some\_services** is a dictionary of services:

some\_services:

- { service\_name: abc, service\_en: True, service\_conf: abc.ini, service\_group:abc\_group }

- { service\_name: def, service\_en: True, service\_conf: def.ini, service\_group:def\_group }

I know **with\_items** isn’t supported with **include** so I get the following error:

1. ERROR: [DEPRECATED]: include + with\_items is a removed deprecated feature, Please update your playbooks.

What would be a reasonable way to implement the above block of code?

Thanks,  
J

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 12, 2015, 10:56pm UTC](https://forum.ansible.com/t/workaround-for-using-a-variable-list-of-vars-with-include/19343/2 "2015-10-12T22:56:53Z")

</div>

actually, in 2.0 we 'resurrect' include + with\_items. so it depends on  
which version of ansible you are running.

---

<div class="post-metadata">

**Author:** ![Bas\_Kamer](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@Bas\_Kamer](https://forum.ansible.com/u/Bas_Kamer)\
**Post date:** [October 13, 2015, 9:40am UTC](https://forum.ansible.com/t/workaround-for-using-a-variable-list-of-vars-with-include/19343/3 "2015-10-13T09:40:46Z")

</div>

yes, however with ansible 2.0-beta1 I see the included task is uh, included. but any task defined in it are not executed.

a playbook such as;

vars:  
mysql\_databases:

- { name: stg\_snd, collation: utf8\_general\_ci, encoding: utf8, replicate: 0, import\_s3\_backup: false}
- { name: dev\_snd, collation: utf8\_general\_ci, encoding: utf8, replicate: 0, import\_s3\_backup: false }
- { name: prd\_snd, collation: utf8\_general\_ci, encoding: utf8, replicate: 0, import\_s3\_backup: true }

tasks:

- name: mysql | import databases from backup  
include: “{{ playbook\_dir }}/roles/provision.mysql/tasks/import\_s3\_backup.yml”  
with\_items: “{{ mysql\_databases | list }}”  
when: “{{ item.import\_s3\_backup | default(false) }} == true”

and this task file

- debug: msg=“Boo”

the output is TASK [mysql | import databases from backup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [s02.localhost] =\> (item={u’collation’: u’utf8\_general\_ci’, u’import\_s3\_backup’: False, u’replicate’: 0, u’name’: u’plhw\_stg\_sandalinos’, u’encoding’: u’utf8’}) =\> {“changed”: false, “item”: {“collation”: “utf8\_general\_ci”, “encoding”: “utf8”, “import\_s3\_backup”: false, “name”: “stg\_snd”, “replicate”: 0}, “skip\_reason”: “Conditional check failed”, “skipped”: true}  
skipping: [s02.localhost] =\> (item={u’collation’: u’utf8\_general\_ci’, u’import\_s3\_backup’: False, u’replicate’: 0, u’name’: u’plhw\_dev\_sandalinos’, u’encoding’: u’utf8’}) =\> {“changed”: false, “item”: {“collation”: “utf8\_general\_ci”, “encoding”: “utf8”, “import\_s3\_backup”: false, “name”: “dev\_snd”, “replicate”: 0}, “skip\_reason”: “Conditional check failed”, “skipped”: true}  
included: {{ playbook\_dir }}/roles/provision.mysql/tasks/import\_s3\_backup.yml for s02.localhost =\> (item={u’collation’: u’utf8\_general\_ci’, u’import\_s3\_backup’: True, u’replicate’: 0, u’name’: u’prd\_snd’, u’encoding’: u’utf8’})

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
s02.localhost : ok=1 changed=0 unreachable=0 failed=0

No ‘Boo’ is outputted.

I can place any string as the include argument (path) no error no different output. It will bravely tell me ‘included: non/existing/path/to/task.yml’, yes that is incorrect

---

<div class="post-metadata">

**Author:** ![Bas\_Kamer](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@Bas\_Kamer](https://forum.ansible.com/u/Bas_Kamer)\
**Post date:** [October 13, 2015, 9:43am UTC](https://forum.ansible.com/t/workaround-for-using-a-variable-list-of-vars-with-include/19343/4 "2015-10-13T09:43:34Z")

</div>

it has been fixed : [https://github.com/ansible/ansible/issues/12654](https://github.com/ansible/ansible/issues/12654)
