using custom vars in group_by

36 views
Skip to first unread message

O. T. Suarez

unread,
Oct 9, 2014, 3:46:38 PM10/9/14
to ansible...@googlegroups.com
Hi,
I want to be able to execute tasks on a subgroup of servers. It can be done via groups ([dbservers_cannary]) in the inventory file, but after checking out group_by funcionality, I thought of just adding a variable to the host in order to identify its pertenence to the subgroup.
This is for the cannary release before full deploy.
The code below doesn't work as originally intented. Any idea what I am missing?
Regards,
Osvaldo


$ cat inventory
[dbservers]
db1 ansible_connection=local deploy=release
db2 ansible_connection=local deploy=cannary
db3 ansible_connection=local deploy=release
[wwwservers]
web1 ansible_connection=local deploy=cannary
web2 ansible_connection=local deploy=release
web3 ansible_connection=local deploy=release
$ cat vars.yml
---
- hosts: all
  gather_facts: false
  tasks:
  - group_by: key=deploy

- name: ping cannary servers
  hosts: cannary
  gather_facts: false
  tasks:
  - name: ping
    action: ping

$ ansible-playbook -i inventory vars.yml

PLAY [all] ******************************************************************** 

TASK: [group_by key=deploy] *************************************************** 
changed: [web1]

PLAY [ping cannary servers] *************************************************** 
skipping: no hosts matched

PLAY RECAP ******************************************************************** 
db1                        : ok=1    changed=1    unreachable=0    failed=0   
...


Reply all
Reply to author
Forward
0 new messages