I am running an Ansible play which uses the serial
property to run against a subset of the hosts at a time.
I would like to get the current serial counter so I can use this to dynamically set a group name in an add_host
task.
For example my hosts file is as follows:
"172.23.130.13",
"172.23.130.34",
"172.23.130.99",
"172.23.130.94"
My play is as follows:
- name: Create Add and Remove Group Batches
gather_facts: false
hosts: all
become: true
no_log: false
serial: 2
tasks:
- add_host:
name: "{{ item.1 }}"
ansible_ssh_port: 2020
group: loadbalancer-{{ <<serial counter here>> }}
action: add
with_indexed_items: "{{ ansible_play_batch }}"
delegate_to: localhost
This play will run twice as serial
is set to 2. I would therefore like 2 groups to be created by the add_host
task. One group called loadbalancer-1
and another called loadbalancer-2
.
The group loadbalancer-1
will contain the first 2 IPs from the hosts file and the group loadbalancer-2
the next 2.
Is this possible?
Thanks for any help people can offer.