debops / ansible-ifupdown

Manage network interface configuration in /etc/network/interfaces
GNU General Public License v3.0
25 stars 14 forks source link

[debops.ifupdown : Generate interface configuration] failure #46

Closed sxpert closed 8 years ago

sxpert commented 8 years ago

I am building this automatic vm installer with pxe booting and stuff, with dhcp. at some point in the script I want to reconfigure the network so as to set a static ip on eth1 (this part is not there yet, am trying to get the dhcp bit on eth0 working first. for some reason it does part of the job, but fails at the configuration file generation task... I have the following as a dependency of a role :

#----------------------
# configure the network interfaces
# 
  - role: 'debops.ifupdown'
    ifupdown_ignore_cap12s: True
    ifupdown_ignore_static: True
    ifupdown_interfaces:
      - iface: 'eth0'
        type: 'interface'
        inet: 'dhcp'

here's the result :

TASK [debops.ifupdown : include] ***********************************************
skipping: [jmmc-ctrl-1]

TASK [debops.ifupdown : Create directory] **************************************
ok: [jmmc-ctrl-1] => (item={u'path': u'/etc/network/interfaces.d'})
ok: [jmmc-ctrl-1] => (item={u'path': u'/etc/network/interfaces.config.d'})

TASK [debops.ifupdown : include] ***********************************************
included: /etc/ansible/roles/debops.ifupdown/tasks/divert_interfaces.yml for jmmc-ctrl-1

TASK [debops.ifupdown : Divert original /etc/network/interfaces] ***************
ok: [jmmc-ctrl-1]

TASK [debops.ifupdown : Provide original interfaces temporarily] ***************
skipping: [jmmc-ctrl-1]

TASK [debops.ifupdown : Remove redundant configuration from original interfaces] ***
skipping: [jmmc-ctrl-1] => (item=^source /etc/network/interfaces.d/*) 
skipping: [jmmc-ctrl-1] => (item=^auto lo) 
skipping: [jmmc-ctrl-1] => (item=^iface lo inet loopback) 

TASK [debops.ifupdown : Create /etc/network/interfaces] ************************
ok: [jmmc-ctrl-1]

TASK [debops.ifupdown : include] ***********************************************
included: /etc/ansible/roles/debops.ifupdown/tasks/check_networkmanager.yml for jmmc-ctrl-1

TASK [debops.ifupdown : Check if Network Manager is installed] *****************
ok: [jmmc-ctrl-1]

TASK [debops.ifupdown : Enable Network Manager support if installed] ***********
skipping: [jmmc-ctrl-1]

TASK [debops.ifupdown : include] ***********************************************
included: /etc/ansible/roles/debops.ifupdown/tasks/generate_interfaces.yml for jmmc-ctrl-1

TASK [debops.ifupdown : Load default interface configuration] ******************
skipping: [jmmc-ctrl-1] => (item=/etc/ansible/roles/debops.ifupdown/vars/default.yml) 

TASK [debops.ifupdown : Prepare interface configuration if not defined] ********
skipping: [jmmc-ctrl-1]

TASK [debops.ifupdown : Prepare interface configuration via dependency if defined] ***
skipping: [jmmc-ctrl-1]

TASK [debops.ifupdown : Gather required network interface capabilities] ********
ok: [jmmc-ctrl-1]

TASK [debops.ifupdown : Add package dependencies for full interface declaration functionality] ***
ok: [jmmc-ctrl-1] => (item=[u'resolvconf', u'bsdutils', u'rsync'])

TASK [debops.ifupdown : Install network reconfiguration script] ****************
ok: [jmmc-ctrl-1]

TASK [debops.ifupdown : Delete interface configuration if requested] ***********
skipping: [jmmc-ctrl-1] => (item={u'iface': u'eth0', u'type': u'interface', u'inet': u'dhcp'}) 

TASK [debops.ifupdown : Generate interface configuration] **********************
failed: [jmmc-ctrl-1] => (item={u'iface': u'eth0', u'type': u'interface', u'inet': u'dhcp'}) => 
{"failed": true, "item": {"iface": "eth0", "inet": "dhcp", "type": "interface"}, "msg": 
"AnsibleUndefinedVariable: Unable to look up a name or access an attribute in template 
string. Make sure your variable name does not contain invalid characters like '-'."}
    to retry, use: --limit @jmmc-control.retry

PLAY RECAP *********************************************************************
jmmc-ctrl-1                : ok=46   changed=13   unreachable=0    failed=1   

the expected behavior should be no visible change from the default configuration

drybjed commented 8 years ago

Hmm, never seen that error yet, I'll test it out.

drybjed commented 8 years ago

@sxpert Well... I've set up a role with dependency on debops.ifupdown with variables you specified and it works, no errors. You probably need to be more specific, or you could try removing part of the template used to generate the configuration until you find which variable doesn't want to cooperate.

sxpert commented 8 years ago

ansible_interfaces is undefined in :

{% if not ifupdown_tpl_generate_interface and not ifupdown_tpl_generate_interface_extended and not ifupdown_tpl_generate_interface_failed and (item.type is undefined or (item.type is defined and item.type == ifupdown_tpl_config_type) and (not ifupdown_tpl_virtual_interface and item.iface in ansible_interfaces) or (item.force is defined and item.force)) %}
{% set ifupdown_tpl_generate_interface = True %}
{% else %}
{% if not ifupdown_tpl_failure_reason %}
{% set ifupdown_tpl_failure_reason = ifupdown_tpl_config_alias | capitalize + ' ' + item.iface + ' not found' %}
{% endif %}
{% endif %}
drybjed commented 8 years ago

@sxpert That's... Do you gather facts when playbook starts?

sxpert commented 8 years ago

hah !!

adding a setup somewhere at the end of my ubuntu_vm role did it ;-)

mebbe there should be something more explicit in the manual, it didn't strike me ;-)

drybjed commented 8 years ago

Well, IIRC Ansible gathers facts automatically by default, you would need to explicitly disable this in the playbook or in ansible.cfg.

sxpert commented 8 years ago

this starts as a role running on the hypervisor as there's no vm working yet

https://github.com/sxpert/jmmc/blob/master/roles/ubuntu-vm/tasks/main.yml

then, we want to change the network configuration of the new vm here :

https://github.com/sxpert/jmmc/blob/master/roles/jmmc-controller/meta/main.yml

drybjed commented 8 years ago

@sxpert Ah, I see... You basically are doing the instantiation and set up in one go. That explains that.

sxpert commented 8 years ago

anyways, thanks for helping ;-)