Skip to content

Instantly share code, notes, and snippets.

@omgjlk
Created August 30, 2019 17:13
Show Gist options
  • Save omgjlk/5abf89139a2ff321635e8bcd65681a7b to your computer and use it in GitHub Desktop.
Save omgjlk/5abf89139a2ff321635e8bcd65681a7b to your computer and use it in GitHub Desktop.
Some Ansible to show what's next in a serial play
---
- name: try a thing
hosts: _cab*
ignore_unreachable: true
gather_facts: false
connection: local
serial: 2
tasks:
- name: what host am I
debug:
var: inventory_hostname
run_once: true
- name: what hosts are in this batch
debug:
var: ansible_play_batch
run_once: true
- name: remaining hosts in this play
debug:
var: ansible_play_hosts[ansible_play_hosts.index(ansible_play_batch[-1])+1:] |length
run_once: true
- name: which hosts are next
debug:
msg: Next hosts are {{ ansible_play_hosts[ansible_play_hosts.index(ansible_play_batch[-1])+1:ansible_play_hosts.index(ansible_play_batch[-1])+3] }}
run_once: true
And here is what it shows:
> pipenv run ansible-playbook -i sites-api-inventory whatsnext.yaml --limit am4-ams
PLAY [try a thing] ********************************************************************************************************************************************
TASK [what host am I] *****************************************************************************************************************************************
ok: [dce-gpanel-1bqb0q2.am4-ams.github.net] => {
"inventory_hostname": "dce-gpanel-1bqb0q2.am4-ams.github.net"
}
TASK [what hosts are in this batch] ***************************************************************************************************************************
ok: [dce-gpanel-1bqb0q2.am4-ams.github.net] => {
"ansible_play_batch": [
"dce-gpanel-1bqb0q2.am4-ams.github.net",
"dce-gpanel-1brlrp2.am4-ams.github.net"
]
}
TASK [remaining hosts in this play] ***************************************************************************************************************************
ok: [dce-gpanel-1bqb0q2.am4-ams.github.net] => {
"ansible_play_hosts[ansible_play_hosts.index(ansible_play_batch[-1])+1:] |length": "139"
}
TASK [which hosts are next] ***********************************************************************************************************************************
ok: [dce-gpanel-1bqb0q2.am4-ams.github.net] => {
"msg": "Next hosts are ['dce-gc2-061e152.am4-ams.github.net', 'db-mysql-a8d24fd.am4-ams.github.net']"
}
PLAY [try a thing] ********************************************************************************************************************************************
TASK [what host am I] *****************************************************************************************************************************************
ok: [dce-gc2-061e152.am4-ams.github.net] => {
"inventory_hostname": "dce-gc2-061e152.am4-ams.github.net"
}
TASK [what hosts are in this batch] ***************************************************************************************************************************
ok: [dce-gc2-061e152.am4-ams.github.net] => {
"ansible_play_batch": [
"dce-gc2-061e152.am4-ams.github.net",
"db-mysql-a8d24fd.am4-ams.github.net"
]
}
TASK [remaining hosts in this play] ***************************************************************************************************************************
ok: [dce-gc2-061e152.am4-ams.github.net] => {
"ansible_play_hosts[ansible_play_hosts.index(ansible_play_batch[-1])+1:] |length": "137"
}
TASK [which hosts are next] ***********************************************************************************************************************************
ok: [dce-gc2-061e152.am4-ams.github.net] => {
"msg": "Next hosts are ['dce-gc2-24debc9.am4-ams.github.net', 'dce-gc2-c9bd2ad.am4-ams.github.net']"
}
PLAY [try a thing] ********************************************************************************************************************************************
TASK [what host am I] *****************************************************************************************************************************************
ok: [dce-gc2-24debc9.am4-ams.github.net] => {
"inventory_hostname": "dce-gc2-24debc9.am4-ams.github.net"
}
TASK [what hosts are in this batch] ***************************************************************************************************************************
ok: [dce-gc2-24debc9.am4-ams.github.net] => {
"ansible_play_batch": [
"dce-gc2-24debc9.am4-ams.github.net",
"dce-gc2-c9bd2ad.am4-ams.github.net"
]
}
TASK [remaining hosts in this play] ***************************************************************************************************************************
ok: [dce-gc2-24debc9.am4-ams.github.net] => {
"ansible_play_hosts[ansible_play_hosts.index(ansible_play_batch[-1])+1:] |length": "135"
}
TASK [which hosts are next] ***********************************************************************************************************************************
ok: [dce-gc2-24debc9.am4-ams.github.net] => {
"msg": "Next hosts are ['metrics-surveyor-8e46c28.am4-ams.github.net', 'glb-director-4c1f0cf.am4-ams.github.net']"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment