Thank you!  That is the solution.

On Thursday, January 17, 2019 at 1:27:40 PM UTC-8, Kai Stian Olstad wrote:
>
> On 17.01.2019 21:25, Robert F wrote: 
> > I have this Ansible inventory file: 
> > 
> >     [fileservers] 
> >     fs01.example.com   ansible_ssh_host=192.168.1.1     
> > ip_addr=192.168.1.1 
> > 
> >     [dbservers] 
> >     db01.example.com   ansible_ssh_host=192.168.1.2     
> > ip_addr=192.168.1.2 
> > 
> >     [webservers] 
> >     web01.example.com   ansible_ssh_host=192.168.1.3     
> > ip_addr=192.168.1.3 
> > 
> >     [cmsservers] 
> >     cms01.example.com   ansible_ssh_host=192.168.1.4     
> > ip_addr=192.168.1.4 
> > 
> > What I want to do is be able to set some facts that contain the host 
> > aliases when I run this playbook on my web01.example.com server: 
> > 
> >     - name: create alias facts 
> >       set_fact: 
> >         file_server_alias: hostvars[{{ inventory_hostname 
> > }}]['groups']['fileservers'][0]  # should get string 'fs01.example.com' 
>
> The syntax is not correct, correct syntax should be 
>    file_server_alias: "{{ 
> hostvars[inventory_hostname]['groups']['fileservers'][0] }}" 
>
> But there is not point in using hostvars in this example since you can 
> just use groups(one of the magic variables in Ansible) 
>    file_server_alias: "{{ groups['fileservers'][0] }}" 
>
> -- 
> Kai Stian Olstad 
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f99ba8c2-8dc1-4720-900e-c4b56682fba2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to