Hosts File - Get group name , only one item from group based on lookup

33 views
Skip to first unread message

Adam McGill

unread,
Apr 12, 2020, 2:04:42 AM4/12/20
to Ansible Project

Is it possible to specify in a playbook hosts value to be a group item from hosts file?

example:

Hosts file contains:

[groupone]
comname1
comname2
comname3

in the playbook would like it to grab the group (groupone) but only apply the playbook routine to a name/value in that group and not all in that group.

groupone | comname2

Stefan Hornburg (Racke)

unread,
Apr 12, 2020, 4:27:40 AM4/12/20
to ansible...@googlegroups.com
On 4/12/20 8:04 AM, Adam McGill wrote:
>
> Is it possible to specify in a playbook hosts value to be a group item from hosts file?
>
> *_example:_*
>
> Hosts file contains:
>
> [groupone]
> comname1
> comname2
> comname3
>
> in the playbook would like it to grab the group (groupone) but only apply the playbook routine to a name/value in that
> group and not all in that group.
>
> groupone | comname2
>

You get the members of this group with the variable groups['groupone'].

Regards
Racke

> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c4715e69-e051-476a-85a7-147737697a7d%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/c4715e69-e051-476a-85a7-147737697a7d%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Adam McGill

unread,
Apr 12, 2020, 1:50:36 PM4/12/20
to Ansible Project
Can i specify it on the hosts: line in the playbook is what i am trying to understand and point it to a value in the group.

hosts: 
['groupone']['comname2'] 
groupone.comname2

gives me warning , could not match supplied host pattern.

tried a few things like above, running into a syntax issue it seems or there isn't a way to do it.  Online documentation referencing a lot with referencing groups to combine or exclude.  Which isn't what i want,
as i just want to reference a name/value in a group.  

Stefan Hornburg (Racke)

unread,
Apr 12, 2020, 2:38:52 PM4/12/20
to ansible...@googlegroups.com
On 4/12/20 7:50 PM, Adam McGill wrote:
> Can i specify it on the hosts: line in the playbook is what i am trying to understand and point it to a value in the group.
>
> hosts: 
> ['groupone']['comname2'] 
> groupone.comname2
>
> gives me warning , could not match supplied host pattern.
>
> tried a few things like above, running into a syntax issue it seems or there isn't a way to do it.  Online documentation
> referencing a lot with referencing groups to combine or exclude.  Which isn't what i want,
> as i just want to reference a name/value in a group. 

There are a number of possibilities which comes to my mind:

- create new group for comname2, which can be included into [groupone] through [groupone:children]
- create dynamic group in the playbook with add_host task
- use --limit on the command line

Regards
Racke

>
> On Sunday, April 12, 2020 at 1:04:42 AM UTC-5, Adam McGill wrote:
>
>
> Is it possible to specify in a playbook hosts value to be a group item from hosts file?
>
> *_example:_*
>
> Hosts file contains:
>
> [groupone]
> comname1
> comname2
> comname3
>
> in the playbook would like it to grab the group (groupone) but only apply the playbook routine to a name/value in
> that group and not all in that group.
>
> groupone | comname2
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/b8afd5ba-eb04-45c6-947c-837722506870%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/b8afd5ba-eb04-45c6-947c-837722506870%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Adam McGill

unread,
Apr 12, 2020, 4:09:00 PM4/12/20
to Ansible Project
I took the route of using children groups.  Too bad there wasn't a way to pull a group and pick a value in that group passing to the Hosts: value in a playbook.  Thanks for the assist/suggestions   
Stefan. 

On Sunday, April 12, 2020 at 1:04:42 AM UTC-5, Adam McGill wrote:
Reply all
Reply to author
Forward
0 new messages