Skip to content

Instantly share code, notes, and snippets.

@agile
Created January 11, 2016 17:34
Show Gist options
  • Save agile/4bc0ea5d244998a33376 to your computer and use it in GitHub Desktop.
Save agile/4bc0ea5d244998a33376 to your computer and use it in GitHub Desktop.
[appservers:children]
datacenter-1
datacenter-2
[datacenter-1]
appservers00[1:3].datacenter-1.example.com
[datacenter-2]
appservers00[1:3].datacenter-2.example.com
# or, should I group the servers how I want them updated instead?
[group1]
appservers001.datacenter-1.example.com
appservers001.datacenter-2.example.com
[group2]
appservers002.datacenter-1.example.com
appservers002.datacenter-2.example.com
[group3]
appservers003.datacenter-1.example.com
appservers003.datacenter-2.example.com
- hosts: appservers
serial: 2
$ ansible-playbook -i inventory.ini --list-hosts playbook.yml
playbook: playbook.yml
play #1 (appservers): host count=6
appservers001.datacenter-1.example.com
appservers002.datacenter-1.example.com
appservers003.datacenter-1.example.com
appservers001.datacenter-2.example.com
appservers002.datacenter-2.example.com
appservers003.datacenter-2.example.com
# which is going to update the hosts serially through that list?
# I want them to be updated in groups by their hostnames: 001, 002, 003, etc..
# I can achieve this by successively calling the playbook with a limit:
$ ansible-playbook -i inventory.ini --list-hosts --limit *001* playbook.yml
playbook: playbook.yml
play #1 (appservers): host count=2
appservers001.datacenter-1.example.com
appservers001.datacenter-2.example.com
# is there another way to organize the inventory, to make it work like this by default?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment