So looks like this feature has been deprecated, i really don't understand why, Ansible CTO's says that we should use instead with_nested but honestly i have no idea how to do it,
Here's my playboook:
- hosts: all
user: root
vars:
- sites:
- site: site1.com
repo: ssh://[email protected]/orgname/reponame
nginx_ssl: true;
copy_init:
- path1/file1.txt
- path2/file2.php
- path2/file3.php
- site: site2.net
repo: ssh://[email protected]/orgname/reposite2
- site: site4.com
repo: ssh://[email protected]/orgname/reposite3
copy_init:
- path2/file2.php
tasks:
- name: Bootstrap Sites
include: bootstrap_site.yml site={{item}}
And the error message when trying to execute this in Ansible 1.6.6:
ERROR: [DEPRECATED]: include + with_items is a removed deprecated feature. Please update your playbooks.
How can i convert this playbook to something that works with this ansible version?
ERROR: [DEPRECATED]: include + with_items is a removed deprecated feature.
A playbook can have 'n' number of plays in a list. In the following example, the first play has set of tasks for ubuntu servers and the second for centos servers.
Ansible's syntax also supports the idea of nested looping. Nested loops in many ways are similar in nature to a set of arrays that would be iterated over using the with_nested operator. Nested loops provide us with a succinct way of iterating over multiple lists within a single task.
with_dict: - "{{ zones_hash }}" declares a list with a dict as the first index, and Ansible rightfully complains since it expects a dict. The solution kfreezy mentioned works since it actually gives a dictionary to with_dict and not a list: with_dict: "{{ zones_hash }}" Follow this answer to receive notifications.
There's no drop-in replacement, unfortunately. Some things you can do:
Pass the list to your included file and iterate there. In your playbook:
vars:
sites:
- site1
- site2
tasks:
- include: bootstrap_site.yml sites={{sites}}
And in bootstrap_site.yml:
- some_Task: ...
with_items: sites
- another_task: ...
with_items: sites
...
Rewrite bootstrap_site as a module (in python, bash, whatever), put it in a library
dir next to your playbook. Then you could do:
- bootstrap_site: site={{item}}
with_items: sites
Update: Ansible V2 is out and brings back the include + with_items combo loop!
I found an answer to circumvent the blahblah-deprecated message... as asked in the original post.
I added a file vars/filenames.yml:
filenames:
- file1
- file2
- file3
Next I read these names at the beginning of the playbook:
- name: read filenames
include_vars: vars/filenames.yml
Then, I can use them later:
- name: Copy files 1
copy: src=/filesrc1/{{ item }} dest=/filedest1/{{ item }} owner=me group=we
with_items: filenames
and so on....
Regards, Tom
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With