Hi,

I am resurrecting this old message (of mine) : the issue
https://github.com/ansible/ansible/issues/4848 has been closed as "you
can't do jinja2", but I think this is an issue in gathering ansible_eth1
fact

any idea ?

Thanks

Le mercredi 6 novembre 2013 17:56:33 UTC+1, Jean Philippe Caruana a écrit :
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I successfully managed to add a private IP address on my servers. I
can see both network interfaces eth0 and eth1 when I ask for the facts
of this server (I stuggled to death to find this command) :

$ ansible server -m setup -i production
"ansible_eth0": {
"active": true,
"device": "eth0",
"ipv4": {
"address": "x.x.x.x",
"netmask": "x.x.x.x",
"network": "x.x.x.x"
},
"ipv6": [
{
"address": "x::x:x:x:x",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "x:x:x:x:x:x",
"module": "e1000e",
"mtu": 1500,
"type": "ether"
},
"ansible_eth1": {
"active": true,
"device": "eth1",
"ipv4": {
"address": "x.x.x.x",
"netmask": "x.x.x.x",
"network": "x.x.x.x"
},
"ipv6": [
{
"address": "x::x:x:x:x",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "x:x:x:x:x:x",
"module": "e1000e",
"mtu": 9000,
"type": "ether"
},


But when I want to access the "ansible_eth1" fact from my playbook :
# dest file is /etc/hosts
# locally resolve private IPs
{% for host in groups['all'] %}
{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }} {{ host }}
{% endfor %}


I get the following error on every single server :
fatal: [server] => {'msg': "One or more undefined variables: 'dict
object' has no attribute 'ipv4'", 'failed': True}


This kind of code worked really good with eth0 ,as you can see in my
fully working iptables template extract :
{% for host in groups['all'] %}
# access from {{ host }}
- -A INPUT -p tcp -m tcp -s {{
hostvars[host]['ansible_eth0']['ipv4']['address'] }} --dport {{
some_port }} -j ACCEPT
{% endfor %}

What am I doing wrong ?
How can I debug this ? I thought "ansible server -m setup -i
production" would provide me the correct information, but I was wrong.

Thanks.
- --
Jean-Philippe Caruana
--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a6c56f5f-d4dd-4312-bbaa-602c27d7f65c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Brian Coca at Nov 21, 2014 at 5:20 pm
    ansible server -m setup -i production, should provide you the correct info.

    I suspect one of your hosts does not have an ipv4 address assigned to eth1.


    --
    Brian Coca

    --
    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-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8%3D5YjtzT1%2Bpq1SiZVGd%3DUYq0JgCNFAXd%3DFGLc%2Bbv5T6Rg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jean-Philippe Caruana at Nov 24, 2014 at 10:38 am
    Thanks, this is helpful.
    As a matter of fact, one of my servers don't have an ipv4 address assign
    to eth1, but does have an ansible_eth1 fact:

             "ansible_eth1": {
                 "active": false,
                 "device": "eth1",
                 <snip>
             },

    I think I can use the active flag to prevent my template from crashing
    for this server:

    {% for host in groups['all'] %}
    {% if hostvars[host]['ansible_eth1']['active'] %}
    {{ hostvars[host]['ansible_eth1']['ipv4']['address'] }} {{ host }}
    {% endif %}
    {% endfor %}


    Le 21/11/2014 18:20, Brian Coca a écrit :
    ansible server -m setup -i production, should provide you the correct info.

    I suspect one of your hosts does not have an ipv4 address assigned to eth1.
    --
    Jean-Philippe Caruana
    http://www.barreverte.fr

    --
    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-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/54730ABA.5040601%40target2sell.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupansible-project @
postedNov 21, '14 at 5:15p
activeNov 24, '14 at 10:38a
posts3
users2

People

Translate

site design / logo © 2022 Grokbase