More details.
vars.yml
fqdn: "{{ hostvars[hostB]['ansible_fqdn'] }}"
address: "{{ hostvars[hostB]['ansible_eth0.ipv4.address'] }}"
---- separator -----
templates/host_def.j2
define host{
use generic-host
host_name {{ fqdn }}
address {{ address }}
max_check_attempts 5
check_command check-host-alive
}
---- separator -----
task.yml
---
- hosts: mon
sudo: yes
vars_files:
- vars.yml
tasks:
- name: Copy Host Definition (Server)
template: src=templates/host_def.j2 dest=/etc/icinga/servers/{{ fqdn
}}.cfg owner=root group=root mode=0644
notify:
- restart icinga
tags:
- server_host
Error:
fatal: [mon] => One or more undefined variables: 'hostB' is undefined
Il giorno mercoledì 16 aprile 2014 16:07:35 UTC+2, Valentino Gagliardi ha
scritto:
>
> Hello friends!
> Almost sure that this is my fault but at this time is still obscure for me
> how to retrieve facts about host B inside a playbook which run for host A.
>
> This is the real case: I want to populate Icinga host definition running
> the playbook on host A, but retrieving facts about monitored host B:
>
> Already tried
> http://docs.ansible.com/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts(templates/host_def.j2)
> :
>
> define host{
> use generic-host
> host {{ hostvars['hostB']['ansible_fqdn'] }}
> address {{ hostvars['hostB']['ansible_eth0.ipv4.address'] }}
> max_check_attempts 5
> BLABLA
> }
>
> but this give me an error. Is this the right way to use magic variables?
>
> Any pointing? Thanks!
>
--
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/712154b7-18a4-46d8-9ab6-6fe0056f89fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.