ansible-collections / cisco.ios

Ansible Network Collection for Cisco IOS
GNU General Public License v3.0
291 stars 171 forks source link

ios_facts can not parse vlan names with spaces #375

Closed donnerhacke closed 3 years ago

donnerhacke commented 3 years ago
SUMMARY

Cisco IOS and ios_vlan can work well with VLAN, which have spaces in their names. ios_facts can not parse such names.

ISSUE TYPE
COMPONENT NAME

cisco.ios.ios_facts

ANSIBLE VERSION
ansible [core 2.11.1]
  config file = /home/iks/.ansible.cfg
  configured module search path = ['/home/iks/.ansible/plugins/modules', '/usr/local/share/py38-ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/iks/.ansible/collections:/usr/local/share/py38-ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Jun 12 2021, 01:13:14) [Clang 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c
  jinja version = 2.11.2
  libyaml = True
COLLECTION VERSION
Collection                    Version
----------------------------- -------
amazon.aws                    1.5.0
ansible.netcommon             2.0.2
ansible.posix                 1.2.0
ansible.utils                 2.1.0
ansible.windows               1.5.0
arista.eos                    2.1.1
awx.awx                       19.0.0
azure.azcollection            1.5.0
check_point.mgmt              2.0.0
chocolatey.chocolatey         1.1.0
cisco.aci                     2.0.0
cisco.asa                     2.0.1
cisco.intersight              1.0.15
cisco.ios                     2.0.1
cisco.iosxr                   2.1.0
cisco.meraki                  2.2.1
cisco.mso                     1.1.0
cisco.nso                     1.0.3
cisco.nxos                    2.2.0
cisco.ucs                     1.6.0
cloudscale_ch.cloud           2.1.0
community.aws                 1.5.0
community.azure               1.0.0
community.crypto              1.6.2
community.digitalocean        1.1.1
community.docker              1.5.0
community.fortios             1.0.0
community.general             3.0.2
community.google              1.0.0
community.grafana             1.2.1
community.hashi_vault         1.1.3
community.hrobot              1.1.1
community.kubernetes          1.2.1
community.kubevirt            1.0.0
community.libvirt             1.0.1
community.mongodb             1.2.1
community.mysql               2.1.0
community.network             3.0.0
community.okd                 1.1.2
community.postgresql          1.2.0
community.proxysql            1.0.0
community.rabbitmq            1.0.3
community.routeros            1.1.0
community.skydive             1.0.0
community.sops                1.0.6
community.vmware              1.9.0
community.windows             1.3.0
community.zabbix              1.3.0
containers.podman             1.5.0
cyberark.conjur               1.1.0
cyberark.pas                  1.0.6
dellemc.enterprise_sonic      1.0.3
dellemc.openmanage            3.3.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.9.0
fortinet.fortimanager         2.0.2
fortinet.fortios              2.0.1
frr.frr                       1.0.3
gluster.gluster               1.0.1
google.cloud                  1.0.2
hetzner.hcloud                1.4.3
hpe.nimble                    1.1.3
ibm.qradar                    1.0.3
infinidat.infinibox           1.2.4
inspur.sm                     1.1.4
junipernetworks.junos         2.1.0
kubernetes.core               1.2.1
mellanox.onyx                 1.0.0
netapp.aws                    21.2.0
netapp.azure                  21.5.0
netapp.cloudmanager           21.5.1
netapp.elementsw              21.3.0
netapp.ontap                  21.5.0
netapp.um_info                21.5.0
netapp_eseries.santricity     1.2.7
netbox.netbox                 3.0.0
ngine_io.cloudstack           2.1.0
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.0
openstack.cloud               1.4.0
openvswitch.openvswitch       2.0.0
ovirt.ovirt                   1.4.2
purestorage.flasharray        1.8.0
purestorage.flashblade        1.6.0
sensu.sensu_go                1.9.4
servicenow.servicenow         1.0.5
splunk.es                     1.0.2
t_systems_mms.icinga_director 1.16.0
theforeman.foreman            2.0.1
vyos.vyos                     2.2.0
wti.remote                    1.0.1
CONFIGURATION
CACHE_PLUGIN(/home/iks/.ansible.cfg) = community.general.yaml
CACHE_PLUGIN_CONNECTION(/home/iks/.ansible.cfg) = /home/iks/.ansible/cache/
DEFAULT_GATHERING(/home/iks/.ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/iks/.ansible.cfg) = ['/home/iks/ansible/hosts']
INTERPRETER_PYTHON(/home/iks/.ansible.cfg) = auto_silent
PLAYBOOK_DIR(/home/iks/.ansible.cfg) = /home/iks/ansible
OS / ENVIRONMENT

FreeBSD 13.0-STABLE #3 stable/13-n245475-bb9dcbf1a243

STEPS TO REPRODUCE
- name: Test VLAN Bug
  hosts: switch
  gather_facts: no

  tasks:
    - name: Create VLAN
      ios_vlan:
        vlan_id: 109
        name: test vlan
        state: present

    - name: Validate VLAN
      ios_command:
        commands:
          - show vlan brief | include _109_
      register: res

    - name: Show output
      debug:
         var: res.stdout

    - name: Gather facts
      ios_facts:
        gather_network_resources:
          - vlans

    - name: Show facts
      debug:
         var: ansible_facts.network_resources.vlans |
           selectattr('vlan_id', '==', 109)

    - name: Remove VLAN
      ios_vlan:
        vlan_id: 109
        state: absent
EXPECTED RESULTS
PLAY [Test VLAN Bug] ***********************************************************

TASK [Create VLAN] *************************************************************
changed: [switch]

TASK [Validate VLAN] ***********************************************************
ok: [switch]

TASK [Show output] *************************************************************
ok: [switch] => {
    "res.stdout": [
        "109  test vlan                        active"
    ]
}

TASK [Gather facts] ************************************************************
ok: [switch]

TASK [Show facts] **************************************************************
ok: [switch] => {
    "ansible_facts.network_resources.vlans | selectattr('vlan_id', '==', 109)": [
        {
            "mtu": 1500,
            "name": "test vlan",
            "shutdown": "disabled",
            "vlan_id": 109
        }
    ]
}

TASK [Remove VLAN] *************************************************************
changed: [switch]

PLAY RECAP *********************************************************************
switch    : ok=6    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ACTUAL RESULTS
TASK [Show facts] **************************************************************
ok: [switch] => {
    "ansible_facts.network_resources.vlans | selectattr('vlan_id', '==', 109)": [
        {
            "mtu": 1500,
            "name": "test",
            "shutdown": "disabled",
            "vlan_id": 109
        }
    ]
}
donnerhacke commented 3 years ago

ios_vlan is not the culprit. It works the same with ios_vlans.

- name: Test VLAN Bug
  hosts: switch
  gather_facts: no

  tasks:
    - name: Create VLAN
      ios_vlans:
        config:
         - name: test vlan
           vlan_id: 109
           state: active
        state: merged

    - name: Validate VLAN
      ios_command:
        commands:
          - show vlan brief | include _109_
      register: res

    - name: Show output
      debug:
         var: res.stdout

    - name: Gather facts
      ios_facts:
        gather_network_resources:
          - vlans

    - name: Show facts
      debug:
         var: ansible_facts.network_resources.vlans |
           selectattr('vlan_id', '==', 109)

    - name: Remove VLAN
      ios_vlans:
        config:
          - vlan_id: 109
        state: deleted
KB-perByte commented 3 years ago

Hi @donnerhacke,


PLAY [Test VLAN Bug] ***********************************************************

TASK [Create VLAN] *************************************************************
changed: [10.8.xx.76]

TASK [Validate VLAN] ***********************************************************
ok: [10.8.xx.76]

TASK [Show output] *************************************************************
ok: [10.8.xx.76] => {
    "res.stdout": [
        "109  test vlan                        active"
    ]
}

TASK [Gather facts] ************************************************************
ok: [10.8.xx.76]

TASK [Show facts] **************************************************************
ok: [10.8.xx.76] => {
    "ansible_facts.network_resources.vlans | selectattr('vlan_id', '==', 109)": [
        {
            "mtu": 1500,
            "name": "test",
            "shutdown": "disabled",
            "vlan_id": 109
        }
    ]
}

TASK [Remove VLAN] *************************************************************
changed: [10.8.xx.76]

PLAY RECAP *********************************************************************
10.8.xx.76                 : ok=6    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Sharing the output of the above play you have shared, I see this issue has been fixed over the latest version of the collection. Please pull in the latest release. Closing the issue. Thank You.

donnerhacke commented 3 years ago

Your own output shows, that the bug is NOT fixed. So why do you close the ticket?