localhost getting all variables from different groups.

33 views
Skip to first unread message

Matt Snoby

unread,
Apr 19, 2017, 3:25:57 PM4/19/17
to Ansible Project
Hello,
I'm looking for advice on how to improve my implementation of my playbook.  I know the way I have designed it is very different from the normal way of doing playbooks.  I have a playbook that controls deploying configuration to 4 different kubernetes clusters.  I use kubectl in a command shell to execute the commands to do deployments. Here is my inventory file:

# Inventory File
#
[east.k.tropo.com]
localhost              ansible_connection
=local


[east2.k.tropo.com]
localhost              ansible_connection
=local


[k8s.int.ops.tropo.com]
localhost              ansible_connection
=local


[k8s.k.dub.tropo.com]
localhost              ansible_connection
=local


#[test.c.tropo.com]
#localhost              ansible_connection=local





I have each cluster setup in it's own group, each group has it's variables in it's own file under inventory/group_vars/ so that when I want to deploy an job to that cluster I would do something like this:

ansible-playbook create.yaml -l k8s.k.dub.tropo.com  --tags foo



My problem is ( I think ) that because each group just has localhost in it, than localhost gets all the variables from the other groups.  This really does break things.  Is there some sort of flag I can set to change this behavior or is there a better way to do what I'm doing?

Thanks,
Matt


Kai Stian Olstad

unread,
Apr 20, 2017, 1:35:49 PM4/20/17
to ansible...@googlegroups.com
Yes, localhost will get them all and the last one is being used.

Since you are not using hostnames in the inventory why not just use some
fake hostname instead of localhost and keep ansible_connection=local.

Since ansible_connection is local it will still run on the localhost.

--
Kai Stian Olstad

Brian Coca

unread,
Apr 20, 2017, 1:39:57 PM4/20/17
to Ansible Project
This will work:

east.k.tropo.com
east2.k.tropo.com
k8s.int.ops.tropo.com
k8s.k.dub.tropo.com
test.c.tropo.com
[group_vars:all]
ansible_connection=local


Just remember that the host is the main object for ansible plays,
groups are just properties of the host and a convenient way to bulk
assign vars. Groups are not their own entity outside of inventory
definition.
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages