Not to flog a dead horse as there are numerous threads about not allowing with_items and includes, but I have a narrower use case that I could really use this for and hopefully someone can help me here.
I have a script that I use to spin up new cloud vm instances, the variables specific to the instance are passed in at runtime, something along the lines of
-
hosts: localhost
connection: local
gather_facts: True -
{include: playbooks/create_instance.yml,
instance_type: ‘c3.xlarge’,
tags: {
hostname: ‘xyz-server’,
cluster_name: ‘{{cluster_name}}’,
ansible_names: [‘xyz-server1’]
},
}
I’d like to be able to add a with_sequence to this so I could spin up more than one at a time. Something along the lines of
-
hosts: localhost
connection: local
gather_facts: True -
{include: playbooks/create_instance.yml,
instance_type: ‘c3.xlarge’,
tags: {
hostname: ‘xyz-server{{item}}’,
cluster_name: ‘{{cluster_name}}’,
dns_names: [‘xyz-server{{item}}’]
},
with_sequence: start={{start}} end={{end}}
}
Unfortunately I get the deprecated warning
ERROR: [DEPRECATED]: include + with_items is a removed deprecated feature. Please update your playbooks.
I realize that its easy to get burned with this, but in this case there is only a single host so no danger of the variables resolving differently on different hosts.
A workaround mentions pushing the loop down into the playbook, but that playbook is pretty modular and calls other playbooks so would require pushing the loop code into each of these.
Any suggestions of how this could be handled? I’m about to resort to a shell script to repeatedly call my playbook but it seems wrong.
Instead of outright vetoing it, might a ‘caveat emptor’ approach be more appropriate, a warning outlining the danger but ultimately letting it execute? If I burn myself I’ll only have myself to blame
thanks
Steve.