using a variable as a group name when executing a task ?

56 views
Skip to first unread message

Alejandro Comisario

unread,
Nov 13, 2015, 10:53:08 AM11/13/15
to Ansible Project
Hi all ! is there any way of achieving the following ?
( i've tried this ones and i get "no hosts matched" )

monitor_group = "glance"

- hosts: "{{ monitor_group }}"
  roles:
    - { role: icinga2-check-commands, tags: ['monitor-cloud'] }

OR

monitor_group = glance

- hosts: "{{ monitor_group }}"
  roles:
    - { role: icinga2-check-commands, tags: ['monitor-cloud'] }

Uwe Sauter

unread,
Nov 13, 2015, 10:58:44 AM11/13/15
to ansible...@googlegroups.com
What about:

- vars:
monitor_group: "glance"
- hosts: "{{ monitor_group }}"
roles:
- { role: icinga2-check-commands, tags: ['monitor-cloud'] }


I'm not saying that this'll work as I am trying to figure out variables myself. But you could give it a try.





Am 13.11.2015 um 16:53 schrieb Alejandro Comisario:
> Hi all ! is there any way of achieving the following ?
> ( i've tried this ones and i get "*no hosts matched*" )
>
> monitor_group = "glance"
>
> - hosts: "{{ monitor_group }}"
> roles:
> - { role: icinga2-check-commands, tags: ['monitor-cloud'] }
>
> OR
>
> monitor_group = glance
>
> - hosts: "{{ monitor_group }}"
> roles:
> - { role: icinga2-check-commands, tags: ['monitor-cloud'] }
>
> --
> 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
> <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c6f7988a-e2b9-49b9-89db-8290f4e1b303%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/c6f7988a-e2b9-49b9-89db-8290f4e1b303%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Alejandro Comisario

unread,
Nov 13, 2015, 11:09:17 AM11/13/15
to Ansible Project, uwe.sa...@gmail.com
Thank for the response, sorry that i didnt clarify this.
The monitor_cloud variable is in the [all:vars] section of the inventory.

On Friday, November 13, 2015 at 12:58:44 PM UTC-3, Uwe Sauter wrote:
What about:

- vars:
  monitor_group: "glance"
- hosts: "{{ monitor_group }}"
  roles:
    - { role: icinga2-check-commands, tags: ['monitor-cloud'] }


I'm not saying that this'll work as I am trying to figure out variables myself. But you could give it a try.





Am 13.11.2015 um 16:53 schrieb Alejandro Comisario:
> Hi all ! is there any way of achieving the following ?
> ( i've tried this ones and i get "*no hosts matched*" )
>
> monitor_group = "glance"
>
> - hosts: "{{ monitor_group }}"
>   roles:
>     - { role: icinga2-check-commands, tags: ['monitor-cloud'] }
>
> OR
>
> monitor_group = glance
>
> - hosts: "{{ monitor_group }}"
>   roles:
>     - { role: icinga2-check-commands, tags: ['monitor-cloud'] }
>
> --
> 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

Uwe Sauter

unread,
Nov 13, 2015, 11:12:41 AM11/13/15
to Alejandro Comisario, Ansible Project

Alejandro Comisario

unread,
Nov 13, 2015, 11:16:05 AM11/13/15
to Ansible Project, alej...@nubeliu.com, uwe.sa...@gmail.com
My problem is that i cant use a variable for the "- host: " part to realize what servers to run on.
>     > <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.

Alejandro Comisario

unread,
Nov 15, 2015, 11:50:36 AM11/15/15
to Ansible Project
anyone ?

Brian Coca

unread,
Nov 15, 2015, 3:17:47 PM11/15/15
to Ansible Project
group_vars/ are loaded AFTER -hosts: so you cannot use them to set the
hosts, you can do this using extra vars though:

ansible-playbook ... play.yml ... -e 'monitor_group=<hostname>'



--
Brian Coca

Alejandro Comisario

unread,
Nov 15, 2015, 3:27:16 PM11/15/15
to ansible...@googlegroups.com
Genius Brian.
thanks so much !


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/bM6kACUiE2Q/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAJ5XC8mfoAi5rZCeAgZp-oZwy0k-S%3DFEwmwtFC1-YmMKEyA6aw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Alejandro Comisario
CTO | NUBELIU
E-mail: alej...@nubeliu.comCell: +54 9 11 3770 1857
_
www.nubeliu.com
Reply all
Reply to author
Forward
0 new messages