netbox-community / ansible_modules

NetBox modules for Ansible using Ansible Collections
GNU General Public License v3.0
329 stars 209 forks source link

[Bug]: Ansible Netbox integration doesn't work anymore after upgrading to NetBox 4.0.3 from NetBox 3.6.7 #1265

Closed kiaz-github closed 2 months ago

kiaz-github commented 3 months ago

Ansible NetBox Collection version

v3.18.0

Ansible version

ansible [core 2.16.7]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/chiara/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/chiara/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True

NetBox version

v4.0.3

Python version

3.10

Steps to Reproduce

     - name: "Netbox: create/update sites"
        netbox.netbox.netbox_site:
          netbox_url: "{{ nb_url }}"
          netbox_token: "{{ nb_token }}"
          validate_certs: no
          data:
            name: "RIZ-{{ item.Kuerzel }}-{{ item.ID }}"
            status: active
            site_group: "riz"
            tenant: "RIZ"
            time_zone: "Europe/Zurich"
            physical_address: "{{ item.Hauptstandort }} \n {{ item.Adresse }} \n {{ item.PLZ }} {{ item.Ort }}"
            comments: "NSN: {{ item.Anschlussnummer }}"
          state: present
        loop: "{{ standort.list }}"
        when:
          - item.ID.startswith('10')
          - item.Status in "{{ site_valid_status_list }}"
        tags:
          - create_site
      This playbook worked before the upgrade.

Expected Behavior

The connection to the NeBox API works and the Ansible Playbook is executed.

Observed Behavior

"Failed to establish connection to NetBox API"

LoneSnowMonkey commented 3 months ago

I encountered this myself as well. I had upgraded my execution environment from before v3.18 release, believe we were using 3.17.0. Recompiled to use latest (3.19.1) release of netbox ansible modules. Worked fine, but this morning I upgraded by Netbox instance from 3.7.3 to 4.0.5. Started getting "Failed to establish connection to NetBox API", even on production playbooks that worked before upgrade. I snapshotted before upgraded Netbox, reverted to my 3.7.3 snapshot, re-ran playbooks that failed and they worked once again. REST calls from dev software worked fine, but in my nginx logs I am seeing 403 HTTP codes from my ansible host when playbooks are run.

UPDATED:

I think I found the behavior causing this. I ran the playbook against a mock server that would print out all incoming HTTP requests. What I saw was that there was an initial GET for hostname/api. Followed later by other calls for hostname/api/status and the like.

The first call for foo/api did not include a token. All subsequent API calls did have a token in header. I pulled Postman up and what I noticed was that if I turned off the Token in my header and did a GET against my 3.X host hostname/api it worked. Same against host upgraded to 4.x and it would give me a 403 error. Not sure where the breaking change comes in here. We could run the hostname/api call with the token the script already has and it should work. FWIW

LoneSnowMonkey commented 3 months ago

The ticket I had opened about the /api 403 behavior was closed as duplicate. The ticket it was duplicate of was closed weeks ago basically saying 'This is the intended behavior, will update documentation to say so'.

Module will need to auth all API calls.

nicolai-hornung-bl commented 3 months ago

Encountering the same issue - none of my playbooks work after upgrading to 4.0.3. Does someone have a workaround that doesn't involve downgrading NetBox again?

kiaz-github commented 3 months ago

Hi all,

I solved my issue as described here: https://github.com/netbox-community/netbox/issues/16414#issuecomment-2151805183

jeffgdotorg commented 3 months ago

I've just released pynetbox 7.3.4, which should address this bug.

LoneSnowMonkey commented 3 months ago

I've just released pynetbox 7.3.4, which should address this bug.

Looks like its working for me now too. Thanks for your work!

rodvand commented 2 months ago

Fixed with pynetbox 7.3.4.