network icon indicating copy to clipboard operation
network copied to clipboard

undefined variables in playbook result in unrelated error message

Open tyll opened this issue 7 years ago • 3 comments

When trying to run a playbook with an undefined variable, the role fails with an error message such as:

TASK [linux-system-roles.network : Install packages] ************************************************************************************************************************************************
fatal: [rhel7b-cloud]: FAILED! => {"msg": "The conditional check 'not network_packages is subset(ansible_facts.packages.keys())' failed. The error was: error while evaluating conditional (not network_packages is subset(ansible_facts.packages.keys())): 'network_iphost' is undefined\n\nThe error appears to have been in '/home/till/scm/network-lsr/tests/roles/linux-system-roles.network/tasks/main.yml': line 14, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# Therefore install packages only when rpm does not find them\n- name: Install packages\n  ^ here\n"}

This is the playbook:

# SPDX-License-Identifier: BSD-3-Clause
---
- hosts: all
  vars:
    network_connections:

      # Create a profile for the underlying device of the VLAN.
      - name: prod2
        type: ethernet
        autoconnect: no
        interface_name: "{{ network_interface_name2 }}"
        ip:
          dhcp4: no
          auto6: no

      # on top of it, create a VLAN with ID 100 and static
      # addressing
      - name: prod2.100
        state: up
        type: vlan
        parent: prod2
        vlan_id: 100
        ip:
          address:
            - "192.0.2.{{ network_iphost }}/24"

  roles:
    - linux-system-roles.network

Commandline:

ansible-playbook -i rhel7b-cloud, -e "network_interface_name2=eth1" eth-with-vlan.yml 

Ideally there would be an independent check for the network_connections to create a clear error message. Maybe just referencing network_connections early helps.

tyll avatar Aug 13 '18 17:08 tyll

'network_iphost' is undefined\n

Is this really an unrelated error message? I would rather say that it pinpoints exactly the problematic spot.

pcahyna avatar Mar 20 '19 09:03 pcahyna

'network_iphost' is undefined\n

Is this really an unrelated error message? I would rather say that it pinpoints exactly the problematic spot.

The unrelated part that I meant is: The conditional check 'not network_packages is subset(ansible_facts.packages.keys())' failed. The error was: error while evaluating conditional (not network_packages is subset(ansible_facts.packages.keys())):

IMHO this part is not helpful.

tyll avatar Mar 20 '19 10:03 tyll

Hello,

Try again your playbook without passing "network_interface_name2=eth1" on CLI, error message is different and doesn't contain name of undefined variable.

nqb avatar Apr 26 '19 11:04 nqb