canonical / ansible-collection

Ansible Collection for interacting with MAAS
GNU General Public License v3.0
11 stars 15 forks source link

Error when Creating a new Physical Interface #28

Closed TheQueasle closed 6 months ago

TheQueasle commented 1 year ago

What

When attempting to create a new interface via maas.maas.network_interface_physical, the following error is thrown but the interface is created within MaaS.

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'to_ansible'
fatal: [localhost]: FAILED! => changed=false 
  module_stderr: |-
    Traceback (most recent call last):
      File "/home/quinnm/.ansible/tmp/ansible-tmp-1690854602.0611262-30070-168320862924394/AnsiballZ_network_interface_physical.py", line 107, in <module>
        _ansiballz_main()
      File "/home/quinnm/.ansible/tmp/ansible-tmp-1690854602.0611262-30070-168320862924394/AnsiballZ_network_interface_physical.py", line 99, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/home/quinnm/.ansible/tmp/ansible-tmp-1690854602.0611262-30070-168320862924394/AnsiballZ_network_interface_physical.py", line 47, in invoke_module
        runpy.run_module(mod_name='ansible_collections.maas.maas.plugins.modules.network_interface_physical', init_globals=dict(_module_fqn='ansible_collections.maas.maas.plugins.modules.network_interface_physical', _modlib_path=modlib_path),
      File "/usr/lib/python3.10/runpy.py", line 224, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_maas.maas.network_interface_physical_payload_o0ps5ehg/ansible_maas.maas.network_interface_physical_payload.zip/ansible_collections/maas/maas/plugins/modules/network_interface_physical.py", line 259, in <module>
      File "/tmp/ansible_maas.maas.network_interface_physical_payload_o0ps5ehg/ansible_maas.maas.network_interface_physical_payload.zip/ansible_collections/maas/maas/plugins/modules/network_interface_physical.py", line 252, in main
      File "/tmp/ansible_maas.maas.network_interface_physical_payload_o0ps5ehg/ansible_maas.maas.network_interface_physical_payload.zip/ansible_collections/maas/maas/plugins/modules/network_interface_physical.py", line 210, in run
      File "/tmp/ansible_maas.maas.network_interface_physical_payload_o0ps5ehg/ansible_maas.maas.network_interface_physical_payload.zip/ansible_collections/maas/maas/plugins/modules/network_interface_physical.py", line 154, in ensure_present
    AttributeError: 'NoneType' object has no attribute 'to_ansible'
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

How

Using the following task, I was attempting to create a new interface on a test system that had a status of Ready in MaaS

    - name: Create Interface
      maas.maas.network_interface_physical:
        cluster_instance:
          host: "{{ maas_api_host }}"
          token_key: "{{ maas_api_token_key }}"
          token_secret: "{{ maas_api_token_secret }}"
          customer_key: "{{ maas_api_customer_key }}"
        machine: "{{ maas_machine_name }}.{{ maas_machine_domain }}"
        state: present
        mac_address: "{{ mac_address }}"
        vlan: 5001
        name: "eno1"
      register: nic_info

Why

In my debugging (aka lots of print statements :smile: ) I've found that for whatever reason, when this tries to run

    after = updated_machine_obj.find_nic_by_mac(
        new_nic_obj.mac_address
    ).to_ansible()

The function updated_machine_obj.find_nic_by_mac() is returning None.

Initial thought was "Maybe this is happening to quick and find_nic_by_mac() is running before the API has the new Nic info recorded. After injecting some time between creation and lookup, I don't think this is the case.

I'm still poking around on this one, but so far I've not stumbled into the solution.

github-actions[bot] commented 7 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 6 months ago

This issue was closed because it has been inactive for 30 days since being marked as stale.