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.