groupname as variable?

89 views
Skip to first unread message

linbo liao

unread,
Nov 10, 2014, 2:16:23 AM11/10/14
to ansible...@googlegroups.com
Hi,

I want set multi-cluster but don't want defined multi-inventory files. Is there any solution for looping a variable defined for a group?

For example, inventory file is

[idc1-master]
host1  cluster-node=idc1-node

[idc1-node]
host2
host3

[idc2-master]
hosti  cluster-node=idc2-node

[idc2-node]
hostj
hostk

playbook file

- name: add nodes
  debug:  msg={{item}}
  with_items:
       cluster-node
  tags:
      - add-node

But this doesn't work, variable cluster-node now is a string not a group. Any help?

Thanks,
Linbo

Brian Coca

unread,
Nov 10, 2014, 8:34:53 AM11/10/14
to ansible...@googlegroups.com
The variable there is defined for a host, not a group, also avoid using dashes (-) in variable names.

It is not clear what you are trying to do here, do you want to add all hosts of a cluster? just the master nodes?


linbo liao

unread,
Nov 12, 2014, 7:31:03 AM11/12/14
to ansible...@googlegroups.com
Yes, want to add all nodes from cluster-node group to cluster.

在 2014年11月10日星期一UTC+8下午9时34分53秒,Brian Coca写道:

Brian Coca

unread,
Nov 12, 2014, 8:56:28 AM11/12/14
to ansible...@googlegroups.com
I believe this is what you want:

in the inventory:
[idc1_node]
....

in the play:

- name: add nodes
  debug:  msg={{item}}
  with_items: groups['idc1_node']
  tags:
      - add-node


--
Brian Coca

linbo liao

unread,
Nov 12, 2014, 9:16:59 PM11/12/14
to ansible...@googlegroups.com
Thanks.

I want setup multi cluster instance. So in the play I can't specify the detailed cluster node groups, what I can do is use variable to cluster node groups.

For example,

[idc1_master]
host1  cluster_node=idc1_node

[idc1_node]
host2
host3

[idc2_master]
hosti  cluster_node=idc2_node

[idc2_node]
hostj
hostk


idc1-master requires idc1_node groups, idc2_master requires idc2_node groups. If playbook use idc1_node, idc2 cluster will use idc1_node, which is not correct.


在 2014年11月12日星期三UTC+8下午9时56分28秒,Brian Coca写道:

Brian Coca

unread,
Nov 13, 2014, 9:09:39 AM11/13/14
to ansible...@googlegroups.com
I'm not sure I understand the problem, you want to create the clusters but are not able to specify them?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/29d9bc6f-97aa-4236-aa17-f893741002b1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

linbo liao

unread,
Nov 17, 2014, 1:35:16 AM11/17/14
to ansible...@googlegroups.com
Yes, different clusters require different node groups.

在 2014年11月13日星期四UTC+8下午10时09分39秒,Brian Coca写道:

Brian Coca

unread,
Nov 17, 2014, 8:10:27 AM11/17/14
to ansible...@googlegroups.com
ok, but you are just defining the master node in one host, you probably want group_vars:

[idc1_node:vars]
cluster_master=host1

[idc1_node]
host1
host2
host3


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages