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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to