Skip to content
This repository has been archived by the owner on Feb 9, 2019. It is now read-only.

vm-template vars overrides the group_vars for the whole play! #30

Open
smossber opened this issue Jan 31, 2019 · 0 comments
Open

vm-template vars overrides the group_vars for the whole play! #30

smossber opened this issue Jan 31, 2019 · 0 comments

Comments

@smossber
Copy link

It seems that Ansible overrides variables set by group_vars when we call on a role like this:
https://github.com/redhatNORDICS/consulting-lab/blob/master/roles/vm-template/tasks/main.yml#L4-L30

- name: Set up template network
  import_role:
    name: libvirt_network
  vars:
    libvirt_networks:
    - name: template
      type: open_network
      address: 172.199.199.0
      interface_address: 172.199.199.1
      netmask: 255.255.255.0
      prefix: 24
      dhcp_range_start: 172.199.199.50
      dhcp_range_stop: 172.199.199.60

- name: iptables temlate network
  import_role:
    name: iptables
  vars:
    libvirt_networks:
    - name: template
      type: open_network
      address: 172.199.199.0
      interface_address: 172.199.199.1
      netmask: 255.255.255.0
      prefix: 24
      dhcp_range_start: 172.199.199.50
      dhcp_range_stop: 172.199.199.60

This is bad because it makes the libvirt_network and iptables role, when called individually, to not have the vars we expect it to have.

First run with

- hosts: labhost
  user: root
  gather_facts: true
  roles:
  - libvirt_network
  - iptables
ansible-playbook libvirt_networks.yml -i inventory 
 [WARNING]: Found both group and host with same name: labhost


PLAY [labhost] ****************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:19 +0100 (0:00:00.069)       0:00:00.069 ****** 
ok: [labhost]

TASK [libvirt_network : define networks] **************************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:20 +0100 (0:00:01.415)       0:00:01.485 ****** 
included: /home/moss/infohub/consulting-lab/roles/libvirt_network/tasks/define_network.yml for labhost
included: /home/moss/infohub/consulting-lab/roles/libvirt_network/tasks/define_network.yml for labhost
included: /home/moss/infohub/consulting-lab/roles/libvirt_network/tasks/define_network.yml for labhost

TASK [libvirt_network : Defining network mgmt] ********************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:21 +0100 (0:00:00.128)       0:00:01.613 ****** 
changed: [labhost]

TASK [libvirt_network : Enable and Autostart virtual network mgmt] ************************************************************************************************************************************************
Thursday 31 January 2019  13:19:21 +0100 (0:00:00.704)       0:00:02.318 ****** 
changed: [labhost]

TASK [libvirt_network : allow forward to vpn network] *************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:22 +0100 (0:00:00.528)       0:00:02.847 ****** 
changed: [labhost]

TASK [libvirt_network : Defining network net1] ********************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:22 +0100 (0:00:00.513)       0:00:03.361 ****** 
changed: [labhost]

TASK [libvirt_network : Enable and Autostart virtual network net1] ************************************************************************************************************************************************
Thursday 31 January 2019  13:19:23 +0100 (0:00:00.476)       0:00:03.837 ****** 
changed: [labhost]

TASK [libvirt_network : allow forward to vpn network] *************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:23 +0100 (0:00:00.474)       0:00:04.312 ****** 
changed: [labhost]

TASK [libvirt_network : Defining network net2] ********************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:24 +0100 (0:00:00.433)       0:00:04.745 ****** 
changed: [labhost]

TASK [libvirt_network : Enable and Autostart virtual network net2] ************************************************************************************************************************************************
Thursday 31 January 2019  13:19:24 +0100 (0:00:00.440)       0:00:05.186 ****** 
changed: [labhost]

TASK [libvirt_network : allow forward to vpn network] *************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:25 +0100 (0:00:00.491)       0:00:05.678 ****** 
changed: [labhost]

TASK [iptables : Allow all related and established connection on FORWARD] *****************************************************************************************************************************************
Thursday 31 January 2019  13:19:25 +0100 (0:00:00.316)       0:00:05.995 ****** 
ok: [labhost]

TASK [iptables : Set default policy on FORWARD to DROP] ***********************************************************************************************************************************************************
Thursday 31 January 2019  13:19:25 +0100 (0:00:00.390)       0:00:06.386 ****** 
ok: [labhost]

TASK [iptables : Configure rules for all libvirt_networks] ********************************************************************************************************************************************************
Thursday 31 January 2019  13:19:26 +0100 (0:00:00.706)       0:00:07.092 ****** 
included: /home/moss/infohub/consulting-lab/roles/iptables/tasks/libvirt-network.yml for labhost
included: /home/moss/infohub/consulting-lab/roles/iptables/tasks/libvirt-network.yml for labhost
included: /home/moss/infohub/consulting-lab/roles/iptables/tasks/libvirt-network.yml for labhost

TASK [iptables : create a list of all networks except mgmt] *******************************************************************************************************************************************************
Thursday 31 January 2019  13:19:26 +0100 (0:00:00.159)       0:00:07.251 ****** 
ok: [labhost]

TASK [iptables : add networks to list except mgmt] ****************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:26 +0100 (0:00:00.084)       0:00:07.336 ****** 
 [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: '{{ network.name }}' not in item.name

skipping: [labhost] => (item={u'name': u'mgmt', u'type': u'open_network', u'prefix': 24, u'interface_address': u'10.5.0.1', u'dhcp_range_start': u'10.5.0.100', u'dhcp_range_stop': u'10.5.0.254', u'address': u'10.0.0.0', u'netmask': u'255.255.255.0'}) 
ok: [labhost] => (item={u'name': u'net1', u'type': u'open_network', u'prefix': 24, u'interface_address': u'10.101.0.1', u'dhcp_range_start': u'10.101.0.2', u'dhcp_range_stop': u'10.101.0.254', u'address': u'10.101.0.0', u'netmask': u'255.255.255.0'})
ok: [labhost] => (item={u'name': u'net2', u'type': u'open_network', u'prefix': 24, u'interface_address': u'10.102.0.1', u'dhcp_range_start': u'10.102.0.2', u'dhcp_range_stop': u'10.102.0.254', u'address': u'10.102.0.0', u'netmask': u'255.255.255.0'})

TASK [iptables : print list] **************************************************************************************************************************************************************************************
Thursday 31 January 2019  13:19:26 +0100 (0:00:00.122)       0:00:07.458 ****** 
ok: [labhost] => {
    "msg": [
        "net1", 
        "net2"
    ]
}

Second run with vm-template in the playbook:

- hosts: labhost
  user: root
  gather_facts: true
  roles:
  - libvirt_network
  - iptables
  - vm-template
ansible-playbook libvirt_networks.yml -i inventory 
 [WARNING]: Found both group and host with same name: labhost


PLAY [labhost] ****************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
Thursday 31 January 2019  13:20:03 +0100 (0:00:00.070)       0:00:00.070 ****** 
ok: [labhost]

TASK [libvirt_network : define networks] **************************************************************************************************************************************************************************
Thursday 31 January 2019  13:20:05 +0100 (0:00:01.569)       0:00:01.640 ****** 
included: /home/moss/infohub/consulting-lab/roles/libvirt_network/tasks/define_network.yml for labhost

TASK [libvirt_network : Defining network template] ****************************************************************************************************************************************************************
Thursday 31 January 2019  13:20:05 +0100 (0:00:00.131)       0:00:01.771 ****** 
changed: [labhost]

TASK [libvirt_network : Enable and Autostart virtual network template] ********************************************************************************************************************************************
Thursday 31 January 2019  13:20:06 +0100 (0:00:00.780)       0:00:02.552 ****** 
changed: [labhost]

TASK [libvirt_network : allow forward to vpn network] *************************************************************************************************************************************************************
Thursday 31 January 2019  13:20:06 +0100 (0:00:00.609)       0:00:03.161 ****** 
ok: [labhost]

TASK [iptables : Allow all related and established connection on FORWARD] *****************************************************************************************************************************************
Thursday 31 January 2019  13:20:07 +0100 (0:00:00.543)       0:00:03.705 ****** 
ok: [labhost]

TASK [iptables : Set default policy on FORWARD to DROP] ***********************************************************************************************************************************************************
Thursday 31 January 2019  13:20:07 +0100 (0:00:00.374)       0:00:04.080 ****** 
ok: [labhost]

TASK [iptables : Configure rules for all libvirt_networks] ********************************************************************************************************************************************************
Thursday 31 January 2019  13:20:07 +0100 (0:00:00.380)       0:00:04.460 ****** 
included: /home/moss/infohub/consulting-lab/roles/iptables/tasks/libvirt-network.yml for labhost

TASK [iptables : create a list of all networks except template] ***************************************************************************************************************************************************
Thursday 31 January 2019  13:20:08 +0100 (0:00:00.149)       0:00:04.609 ****** 
ok: [labhost]

TASK [iptables : add networks to list except template] ************************************************************************************************************************************************************
Thursday 31 January 2019  13:20:08 +0100 (0:00:00.122)       0:00:04.731 ****** 
 [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: '{{ network.name }}' not in item.name

skipping: [labhost] => (item={u'name': u'template', u'type': u'open_network', u'prefix': 24, u'interface_address': u'172.199.199.1', u'dhcp_range_start': u'172.199.199.50', u'dhcp_range_stop': u'172.199.199.60', u'address': u'172.199.199.0', u'netmask': u'255.255.255.0'}) 

TASK [iptables : print list] **************************************************************************************************************************************************************************************
Thursday 31 January 2019  13:20:08 +0100 (0:00:00.086)       0:00:04.818 ****** 
ok: [labhost] => {
    "msg": []
}
smossber pushed a commit that referenced this issue Jan 31, 2019
So the vars we supply the role with doesn't override our group_vars. 
Described in #30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant