Skip to content

Instantly share code, notes, and snippets.

@richard-scott
Forked from halberom/play.yml
Created October 1, 2019 12:57
Show Gist options
  • Save richard-scott/0e12d7b109422bc6b30005a675017b11 to your computer and use it in GitHub Desktop.
Save richard-scott/0e12d7b109422bc6b30005a675017b11 to your computer and use it in GitHub Desktop.
ansible - example of dynamic even/odd groups
# requirement
# given 2 groups (A and B), target 50% of each for code deploy
- hosts: localhost
tasks:
# this might need to be group_by or add_host
- set_fact:
even: "{{ groups['groupA'][::2] | union(groups['groupB'][::2] }}"
odd: "{{ groups['groupA'][1::2] | union(groups['groupB'][1::2] }}"
- hosts: even
roles:
- deploy something
- hosts: odd
roles:
- deploy something
# it may also be possible to do
#- hosts: even;odd
# serial: 50%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment