How to orchestrate master/slave configuration with Ansible group_by, if that's the proper approach?

25 views
Skip to first unread message

ZillaYT

unread,
Apr 18, 2018, 11:39:02 AM4/18/18
to Ansible Project
I'm setting up a Github master/slave configuration via Ansible role.I set up my github inventory file looks like this

[github1]
github1
.domain.com

[github2]
github2
.domain.com

[github3]
github3
.domain.com

(more node host groups)

[github1:vars]
master
=github1
slaves
=['github2', 'github3']

(more vars similar to above, denoting master and slaves of other nodes)

I run my playbook this way

$ ansible-playbook inventory/github github-install.yml -l github1

and my playbook looks like

---
- hosts: github

  vars
:
    upgrade_master_only
: no
    upgrade_slaves_only
: on

# I know script from this point on doesn't work, this is just pseudo-code to convey the idea
  tasks
:
    group_by
:
        key
: gh_{{ master }}
        key
: gh_{{ slaves }}

# Upgrade the master node, unless user elects to only upgrade slaves
- hosts: gh_master
  roles
:
 
- {role: github-master, when: not upgrade_slaves_only }

# Upgrade all slave nodes, unless user elects to only upgrade the master
- hosts: gh_slaves
  roles
:
 
- {role: github-slaves, when: not upgrade_master_only }


My question is, how can I make the group_by work to give me a group that contains the github1 master, and another group that contains the github1 slaves?

I hope that makes sense.

ZillaYT

unread,
Apr 19, 2018, 10:03:04 AM4/19/18
to Ansible Project
IOW, I want to create a host group from the master and slaves vars of the passed-in limit, github1 in this case.
Reply all
Reply to author
Forward
0 new messages