Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apparent uniqueness issue with module_bay_template module #486

Open
netgirard opened this issue Jan 17, 2025 · 3 comments · May be fixed by #488
Open

Apparent uniqueness issue with module_bay_template module #486

netgirard opened this issue Jan 17, 2025 · 3 comments · May be fixed by #488
Assignees

Comments

@netgirard
Copy link
Contributor

netgirard commented Jan 17, 2025

There appears to be a uniqueness issue with the module_bay_template module where module bays with the same name on different devices are stepping on one another. So if I invoke the module to create a 'Slot 1' module bay template on say a Nexus 7k, and then I invoke the module again to create a module bay template also called 'Slot 1' on a Nexus 9k chassis, the module is incorrectly updating the existing object, instead of determining that it needs to be a separate object.

I have not fully absorbed the working of the class structure underlying the modules, but these two lines might be relevant:
Interface templates work fine, i.e. multiple mgmt0 ports on multiple devices, and that seems to have its uniqueness defined here with both name and device_type:
https://github.com/nautobot/nautobot-ansible/blob/develop/plugins/module_utils/utils.py#L405

While module_bay_template is defined here with just name:
https://github.com/nautobot/nautobot-ansible/blob/develop/plugins/module_utils/utils.py#L419

Actually, looks like that is the only _template key that does not reference device_type for uniqueness.

Edit: Tried updating that line locally, does not affect the behavior.

@netgirard
Copy link
Contributor Author

Simple example playbook:

---
- name: Recreate module bay issue
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Add manufacturers
      networktocode.nautobot.manufacturer:
        name: Cisco
        state: present
        validate_certs: false

    - name: Add device types
      networktocode.nautobot.device_type:
        model: "{{ item['model'] }}"
        manufacturer: "{{ item['manufacturer'] }}"
        state: present
        validate_certs: false
      loop:
        - model: Device1
          manufacturer: Cisco
        - model: Device2
          manufacturer: Cisco


    - name: Add module bay templates
      networktocode.nautobot.module_bay_template:
        name: "{{ item['name'] }}"
        position: "{{ item['position'] }}"
        device_type: "{{ item['device_type'] }}"
        state: present
        validate_certs: false
      loop:
        - device_type: Device1
          name: Slot 1
          position: '1'
        - device_type: Device2
          name: Slot 1
          position: '1'
      register: module_bay_template_adds
ansible-playbook recreate_playbook.yml 
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Recreate module bay issue] ****************************************************************************************************************************************************************************************

TASK [Add manufacturers] ************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Add device types] *************************************************************************************************************************************************************************************************
ok: [localhost] => (item={'model': 'Device1', 'manufacturer': 'Cisco'})
ok: [localhost] => (item={'model': 'Device2', 'manufacturer': 'Cisco'})

TASK [Add module bay templates] *****************************************************************************************************************************************************************************************
changed: [localhost] => (item={'device_type': 'Device1', 'name': 'Slot 1', 'position': '1'})
changed: [localhost] => (item={'device_type': 'Device2', 'name': 'Slot 1', 'position': '1'})

PLAY RECAP **************************************************************************************************************************************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Image

Image

@joewesch
Copy link
Contributor

You are correct, adding device_type to this line did in fact fix it. I think we should also change it to be required on the module.

Do you have the cycles to put in the PR or would you like us to take care of it?

@joewesch joewesch self-assigned this Jan 22, 2025
@netgirard
Copy link
Contributor Author

Thanks for doing the PR, had not checked on the status, and like I said, it didn't seem to fix it when I did it, but I only did device_type, and it looks like you did device_type and module_type in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants