CiscoDevNet / ansible-cml

17 stars 21 forks source link

cml_lab_facts: "Can’t get L3 address of an external_connector" #34

Open sky-joker opened 2 months ago

sky-joker commented 2 months ago
SUMMARY

I tried to gather lab information from my CML2 environment, but the following error occurred, preventing me from doing so.

(snip)
  File \"/xxx/venv/lib/python3.9/site-packages/httpx/_models.py\", line 759, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://100.64.17.16/api/v0/labs/085f1bc7-a471-4326-b0cf-3e90de055f4f/nodes/a96abfcf-061c-484e-b308-1f61d830488d/layer3_addresses'
Can't get L3 addresses of an external_connector.
", "module_stdout": "", "msg": "MODULE FAILURE
See stdout/stderr for the exact error", "rc": 1}

I created the lab structure shown below.

[ext-conn-0] -- G0/0[iosvl2-0]

The configuration for ext-conn-0 is the system bridge.

COMPONENT NAME
ANSIBLE AND LIBRARIES VERSION
% pip list | grep -e virl -e ansible
ansible-core      2.14.14
virl2_client      2.7.0
COLLECTION VERSION

latest

OS/ENVIRONMENT

CML2.7

CONFIGURATION
% ansible-config dump --only-changed
CONFIG_FILE() = None
STEPS TO REPRODUCE

I created the playbook and run it.

---
- name: Example
  hosts: localhost
  gather_facts: false
  vars:
    cml_host: 100.64.17.16
    cml_username: admin
    cml_password: secret
    cml_lab: Example
    ansible_python_interpreter: /<PATH>/venv/bin/python
  tasks:
    - name: Example
      cisco.cml.cml_lab_facts:
        host: "{{ cml_host }}"
        user: "{{ cml_username }}"
        password: "{{ cml_password }}"
        validate_certs: false
        lab: "{{ cml_lab }}"
      register: results

    - debug: msg="{{ results }}"
EXPECTED RESULTS

I expected to gather the lab information.

ACTUAL RESULTS

The following error occurred:

httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://100.64.17.16/api/v0/labs/085f1bc7-a471-4326-b0cf-3e90de055f4f/nodes/a96abfcf-061c-484e-b308-1f61d830488d/layer3_addresses'
Can't get L3 addresses of an external_connector.

When ext-conn-0 does not exist, the module works correctly.

shawnjury commented 2 months ago

This also happens with cisco.cml.inventory (cml_inventory.py file).

I made these changes in the following locations:

inventory/cml_inventory.py: Line 206 modules/cml_lab_facts.py: Line 105

        for interface in node.interfaces():
            no_ips_list = ["external_connector","unmanaged_switch"]
            if node.state == 'BOOTED' and node.node_definition not in no_ips_list:

I'm sure you'll want to clean up the var name, but this allows my external_connector and unmanaged_switch to be found and added to the inventory without the script trying to discover IPs.

zendritic commented 1 month ago

I can't use the wait param on the clean playbook until this is fixed