Ansible. How to choose N hosts from group -
assume group has 10 hosts.
how run playbook on n hosts 10. n arbitrary value 1 10.
example:
- hosts: groups['group_name'][1:3] works.
but doesn't work if instead of 3 use variable, this
- hosts: groups['group_name'][1:n]
it random n, first n, last n ever.
thank you.
this work absolutely fine in ansible 2.1:
--- - hosts: gather_facts: no tasks: - group_by: key=limited_selection when: play_hosts.index(inventory_hostname) < max_index | int - hosts: limited_selection gather_facts: no tasks: - debug: msg="i'm in limited selection group!"
exec this: ansible-playbook -e max_index=3 playbook.yml
or define max_index
somewhere else.
Comments
Post a Comment