Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop over playbook include?

(I'm currently running Ansible 2.1)

I have a playbook that gathers a list of elements and I have another playbook (that calls different hosts and whatnot) using said element as the basis for most operations. Therefore, whenever I use with_items over the playbook, it causes an error.

The loop control section of the docs say that "In 2.0 you are again able to use with_ loops and task includes (but not playbook includes) ". Is there a workaround? I really need to be able to call multiple hosts in an included playbook that runs over a set of entries. Any workarounds, ideas for such or anything are greatly appreciated!

P.S. I could technically command: ansible-playbook but I dont want to go down that rabbit hole if necessary

like image 412
esamudio Avatar asked Sep 15 '26 00:09

esamudio


1 Answers

I think I faced same issues, and by the way, migrating to shows more than in 'item' already in use. refering to http://docs.ansible.com/ansible/playbooks_best_practices.html , you should have an inventory (that contains all your hosts), and a master playbook (even if theorical). A good way, instead of including playbooks, is to design roles, even if empty. Try to find a "common" role for everything that could be applied to most of your hosts.Then, include additional roles depending of usage, this will permit you to trigg on correct hosts. You can also have roles that do nothing (meaning, nothing in 'tasks'), but that contain set of variables that can be common for two roles (you avoid then duplicate entries).

like image 194
limace255 Avatar answered Sep 17 '26 15:09

limace255



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!