not able to reference fact for network interface in the template

60 views
Skip to first unread message

Greg M

unread,
Jul 23, 2014, 5:34:40 PM7/23/14
to ansible...@googlegroups.com

Helo all,


I wonder if I can get some help with referencing facts in template.

I ma not able to reference:


every time I run my play, the file on the host shows:


carp0_ip=””


and the same line in my template:


carp0_ip=”{{ ansible_carp0[“ipv4”][“address”] }}”


this is the snippet from running: ansible server -m setup


"ansible_carp0": {
"device": "carp0",
"flags": [
"UP",
"BROADCAST",
"RUNNING",
"SI
"ipv4": [
{
"address": "10.0.0.33",
"broadcast": "10.0.0.255",
"netmask": "255.255.255.0",
"network": "10.0.0.0"
}
],
"ipv6": [
{
"address": "fe80::200:5eff:fe00:101%carp0",
"prefix": "64",
"scope": "0x4"
}
],
"macaddress": "00:00:5e:00:01:04",
"mtu": "1500",
"status": "master",
"type": "unknown"
},


host where ansible is installed: CentOS 6.5

ansible version: 1.6.6

host I'm pulling facts from: OpenBSD 5.5




Thank you


Greg

Michael DeHaan

unread,
Jul 23, 2014, 6:12:52 PM7/23/14
to ansible...@googlegroups.com
Hmm, can we see a full playbook so we can understand a bit more in context?





Greg

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d4820ae0-eae3-4ad6-aef8-b1570a27d11f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Greg M

unread,
Jul 24, 2014, 9:21:13 AM7/24/14
to ansible...@googlegroups.com
template/relayd.yml.j2:


# {{ ansible_managed }}
#

#
# Macros
#
carp0_ip="{{ ansible_carp0["ipv4"]["address"] }}"
webhost="{{ web_server }}"

#
# Global Options
#

interval 10
log updates
prefork 5
timeout 3000

...
# more in the relayd.conf.j2 file, is removed

the web_server comes from variable file, but the carp0_ip is pulled from facts when the play is run
as user ansible, using sudo 


and the play file: task/main.yml:


---
# file: roles/proxy_server/tasks/main.yml


# carp0 interface
- name: carp0 interface file
  template: src=hostname.carp0.j2 dest=/etc/hostname.carp0 owner=root group=wheel mode=0640

- name: install relayd.conf
  template: src=relayd.conf.j2 dest=/etc/relayd.conf owner=root group=wheel mode=0644
  notify:
  - restart relayd

- name: start relayd
  service: name=relayd state=started

# EOF

  Also one more time the snipet  of the command: ansible proxy_server -m setup (the original file was not complete(damaged))
  

       "ansible_architecture": "amd64", 
        "ansible_carp0": {
            "device": "carp0", 
            "flags": [
                "UP", 
                "BROADCAST", 
                "RUNNING", 
                "SIMPLEX", 
                "MULTICAST"
            ], 
            "ipv4": [
                {
                    "address": "10.0.0.33", 
                    "broadcast": "10.0.0.255", 
                    "netmask": "255.255.255.0", 
                    "network": "10.0.0.0"
                }
            ], 
            "ipv6": [
                {
                    "address": "fe80::200:5eff:fe00:101%carp0", 
                    "prefix": "64", 
                    "scope": "0x4"
                }
            ], 
            "macaddress": "00:00:5e:00:01:01", 
            "mtu": "1500", 
            "status": "master", 
            "type": "unknown"
        }, 
        "ansible_date_time":

Greg M

unread,
Jul 28, 2014, 5:26:48 PM7/28/14
to ansible...@googlegroups.com
 Thank you for your replay.
after farther testing i was able to reproduce the error
the error only shows on BSD system (Open, Free)

sample host file:

# ansible host file
#
# testing

openbsd_host    ansible_ssh_host=owaa
linux_host      ansible_ssh_host=metis
freebsd_host    ansible_ssh_host=hosta

[linux_servers]
linux_host

[openbsd_servers]
openbsd_host

[freebsd_servers]
freebsd_host

[freebsd_servers:vars]
ansible_python_interpreter=/usr/local/bin/python2

[openbsd_servers:vars]
ansible_python_interpreter=/usr/local/bin/python

[linux_servers:vars]
ansible_python_interpreter=/usr/bin/python



sample play file:

---
# test.yml

- hosts: linux_host
 remote_user: gregm

 tasks:
 # name: address (frrebsd and openbsd replace with em0 ans nic)
 - debug: msg={{ ansible_eth0.ipv4.address }}


  
when the play is run against linux box:


PLAY [linux_host] *************************************************************

GATHERING FACTS ***************************************************************
ok: [linux_host]

TASK: [debug msg={{ansible_eth0.ipv4.address}}] *******************************
ok: [linux_host] => {
"msg": "192.168.0.7"
}

PLAY RECAP ********************************************************************
linux_host                 : ok=2    changed=0    unreachable=0    failed=0




but when  run against any of the BSD system: 


PLAY [openbsd_host] ***********************************************************

GATHERING FACTS ***************************************************************
ok: [openbsd_host]

TASK: [debug msg={{ansible_em0.ipv4.address}}] ********************************
ok: [openbsd_host] => {
"msg": "{{ansible_em0.ipv4.address}}"
}

PLAY RECAP ********************************************************************
openbsd_host               : ok=2    changed=0    unreachable=0    failed=0


i hope it will help

Thank you
Greg

Reply all
Reply to author
Forward
0 new messages