Re: [ansible-project] obtaining hostnames and groups

2019-02-21 Thread Swaroop VR
Thanks Steve.. It worked

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/004a3839-9977-4b3a-a253-05a776e54566%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] obtaining hostnames and groups

2019-02-20 Thread S C Rigler
Use "{{ group_names }}".  There can be more than one group, so you'll
likely need to join them with something like "{{ group_names | join(',
') }}"

--Steve

On Wed, Feb 20, 2019 at 9:26 AM Swaroop VR  wrote:
>
> Hi All,
>
> We are trying to fetch the group names inside the host file in our playbook.
>
> e.g. this is my hostfile
>
> *
> [group1]
> host1
> host2
>
> [group2]
> host3
> host4
>
> [group3]
> host5
> host6
>
> [group4]
> host7
> host8
>
> ***
>
> And my playbook will be looking like this which takes all the host inside the 
> inventory file.
>
> 
> ---
> - name: "Fetch host"
>   hosts: all
>   remote_user: c4972295
>   gather_facts: True
>
>   tasks:
>- name: obtaining hostnames and groups
>  shell: "echo {{ inventory_hostname }},**(( I have to print the group 
> name here )) **"
>  register: groups
>
> **
>
> So I want to print the name of the group from the host file and obtain the 
> output in stdout_lines of a register so that I can use it for another 
> iteration purpose.
>
>
> looking forward for help.
>
> Thanks in Advance.
> Swaroop
>
>
> --
> 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-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/c7b110f2-cbfa-4840-b845-f35b8e043bc6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFbiokeNb6BKU8MLPc_PEK%3D0UJ8EEbjCE1JFiCBQV3K3AWiLFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] obtaining hostnames and groups

2019-02-20 Thread Swaroop VR
Hi All,

We are trying to fetch the group names inside the host file in our 
playbook. 

e.g. this is my hostfile

*
[group1]
host1
host2

[group2]
host3
host4

[group3]
host5
host6

[group4]
host7
host8

***

And my playbook will be looking like this which takes all the host inside 
the inventory file. 


---
- name: "Fetch host"
  hosts: all
  remote_user: c4972295
  gather_facts: True
 
  tasks:
   - name: obtaining hostnames and groups 
 shell: "echo {{ inventory_hostname }},**(( I have to print the 
group name here )) **"
 register: groups

**

So I want to print the name of the group from the host file and obtain the 
output in stdout_lines of a register so that I can use it for another 
iteration purpose. 


looking forward for help. 

Thanks in Advance. 
Swaroop


-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c7b110f2-cbfa-4840-b845-f35b8e043bc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.