Since you appear to be walking over "hostvars" are you trying to have a
template that includes the variables for every host in a certain group?

If so, we know how to do that.

Let us know.




On Sun, Jun 1, 2014 at 10:28 AM, Valentino Gagliardi <
[email protected]> wrote:

> Hello friends
> maybe a noob question but I'm unable to get host variable work as
> expected. This is my question.
>
> Given this template:
>
> object Host "{{ hostvars[item]['ansible_fqdn'] }}" {
>   import "generic-host"
>   address = "{{ hostvars[item]['ansible_eth0']['ipv4']['address'] }}"
>   vars.os = "Linux"
>   vars.sla = "24x7"
>   vars.http = "yes"
>   vars.smtp = "yes"
> }
>
> generated by this task:
>
> - name: Copy Host Definitions
>   template: src=host_def.j2
>             dest={{ icinga2_hosts_dir }}{{ hostvars[item]['ansible_fqdn']
> }}.conf
>             owner=root
>             group=root
>             mode=0644
>   with_items: groups['monitored']
>   notify:
>    - restart icinga2
>
> How I can access an host variable eventually defined in inventory?
>
> [monitored:children]
> myservers
>
> [myserver]
> host1 vars_http=no
>
> What I want to do is something like this:
>
> object Host "{{ hostvars[item]['ansible_fqdn'] }}" {
>   import "generic-host"
>   address = "{{ hostvars[item]['ansible_eth0']['ipv4']['address'] }}"
>   vars.os = "Linux"
>   vars.sla = "24x7"
> {% if vars_http == "no" %}
>   vars.http = "no"
> {% else %}
>   vars.http = "yes"
> {% endif %}
>   vars.smtp = "yes"
> }
>
> Thanks for support.
>
> --
> 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/ba7b9704-ed42-4054-ab2b-95595a9dcaf0%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/ba7b9704-ed42-4054-ab2b-95595a9dcaf0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 [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/CA%2BnsWgzvOPta%2BovD6Vrz73-wPBX%3DMpwXAu3HDHSHS6NObz%2BX7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to