netbox-community / ansible_modules

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

Module netbox_device_interface doesn't seems to work properly #23

Closed achrstl closed 4 years ago

achrstl commented 4 years ago
ISSUE TYPE
SUMMARY

I'm currently using your collection with "netbox_device", "netbox_ip_address" and "netbox_device_interface". But with the last one it seem's that ansible doesn't find any action related.

Ansible version: 2.8.5 Netbox version: 2.6.5

I have this message :

"ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The offending line appears to be:

STEPS TO REPRODUCE

I'm using examples in your modules documentation, so netbox_device and netbox_ip_address are working but not netbox_device_interface


- name: Create device within Netbox with only required information
  collections:
     - fragmentedpacket.netbox_modules
  netbox_device:
    netbox_url: "{{ net_url }}"
    netbox_token: "{{ net_token }}"
    data:
      name: "{{ inventory_hostname }}"
      device_type: "{{ type }}"
      platform: "{{ platform }}"
      device_role: "{{ role }}"
      site: "{{ site }}"
      rack: "{{ rack }}"
      position: "{{ position }}"
      face: "{{ face }}"
    state: "{{ state }}"

- name: Create device interface with only required information
  collections:
     - fragmentedpacket.netbox_modules
  netbox_device_interface:
    netbox_url: "{{ net_url }}"
    netbox_token: "{{ net_token }}"
    data:
      device: "{{ inventory_hostname }}"
      name: Vme.0
    state: "{{ state }}"

- name: Create management IP linked to the device
  collections:
     - fragmentedpacket.netbox_modules
  netbox_ip_address:
    netbox_url: "{{ net_url }}"
    netbox_token: "{{ net_token }}"
    data:
      address: "{{ ansible_host }}"
      description: "Mgmt : {{ inventory_hostname }}"
      interface:
        name: Vme.0
        device: "{{ inventory_hostname }}"
    state: "{{ state }}"
EXPECTED RESULTS

Create a device with one interface Vme.0 and one IP attached to it.

ACTUAL RESULTS

If i'm running the two task without netbox_device_interface, the device is created and i can create one IP.

So for the moment i'm using the official "netbox_interface" and it's working like expected. But if i could use all your modules it would be great :)

FragmentedPacket commented 4 years ago

@achrstl You have to move the collections into the play definition. If you look at the example carefully, it'll show how to add the collections at the play level.

You can also do it at the task level by doing this:

fragmentedpacket.netbox_modules.netbox_ip_address:
  netbox_url: XXXX
  netbox_token: XXXX
  data:
    somedata:
achrstl commented 4 years ago

Thanks for your reply ! Indeed it's working when i'm calling the module with fragmentedpacket.netbox_modules.netbox_device_interface

But why the others are working with ?

  collections:
     - fragmentedpacket.netbox_modules

And i try to set the collection in my playbook but it seems that it wasn't taking in consideration by ansible.

---
- name: Add devices in netbox
  hosts: all
  gather_facts: False
  connection: local
  collections:
    - fragmentedpacket.netbox_modules

  vars:
    net_url: http://xyz
    state: present

  roles:
    - netbox_network_device

With this error :

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
FragmentedPacket commented 4 years ago

Can you post your whole playbook without any sensitive information and I can help to see where something might be going wrong?

achrstl commented 4 years ago

My playbook : insert_device_into_netbox.yml

---
- name: Add devices in netbox
  hosts: test-device.yml
  gather_facts: False
  connection: local

  vars:
    net_url: http://xyz
    state: present

  roles:
    - netbox_network_device

For the moment there is only one task in my role "netbox_network_device"

├── ansible.cfg
├── inventories
│   ├── development
│   │   ├── group_vars
│   │   └── host_vars
│   └── production
│       ├── group_vars
│       │   ├── all.yml
│       ├── host_vars
│       │   ├── test-device.yml
│       └── hosts
├── playbooks
│   ├── network
│   │   ├── juniper
│   └── system
│       └── insert_device_into_netbox.yml
├── roles
│   ├── netbox_network_device
│   │   ├── defaults
│   │   │   └── main.yml  --> empty
│   │   ├── tasks
│   │   │   └── main.yml
│   │   ├── templates
│   │   └── vars
│   │       └── main.yml --> empty
- name: Create device within Netbox with only required information
  collections:
     - fragmentedpacket.netbox_modules
  netbox_device:
    netbox_url: "{{ net_url }}"
    netbox_token: "{{ net_token }}"
    data:
      name: "{{ inventory_hostname }}"
      device_type: "{{ type }}"
      platform: "{{ platform }}"
      device_role: "{{ role }}"
      site: "{{ site }}"
      rack: "{{ rack }}"
      position: "{{ position }}"
      face: "{{ face }}"
    state: "{{ state }}"

- name: Create device interface with only required information
  collections:
     - fragmentedpacket.netbox_modules
  netbox_device_interface:
    netbox_url: "{{ net_url }}"
    netbox_token: "{{ net_token }}"
    data:
      device: "{{ inventory_hostname }}"
      name: Vme.0
    state: "{{ state }}"

- name: Create management IP linked to the device
  collections:
     - fragmentedpacket.netbox_modules
  netbox_ip_address:
    netbox_url: "{{ net_url }}"
    netbox_token: "{{ net_token }}"
    data:
      address: "{{ ansible_host }}"
      description: "Mgmt : {{ inventory_hostname }}"
      interface:
        name: Vme.0
        device: "{{ inventory_hostname }}"
    state: "{{ state }}"
FragmentedPacket commented 4 years ago

If you do a debug -vvv I bet the modules it is using is the Netbox modules within Ansible core.

What version of Ansible are you using? I just tested on 2.9.0rc2 and it worked just as you have yours laid out in your most recent post.

achrstl commented 4 years ago

To summarize, if I want to use the three modules as above I have this error:


The error appears to be in '/Users/antoine/Documents/git/network-automation/ansible/roles/netbox_network_device/tasks/main.yml': line 21, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Create device interface with only required information
  ^ here

He is failing before showing the collections used.

Then i tried to run only the first and third tasks "netbox_device and netbox_ip_address"

It works with the right modules :

Using module_utils file ansible_collections/fragmentedpacket/netbox_modules/plugins/module_utils/netbox_dcim
Using module_utils file ansible_collections
Using module_utils file /Users/antoine/.pyenv/versions/3.7.4/lib/python3.7/site-packages/ansible/module_utils/basic.py
Using module_utils file ansible_collections/fragmentedpacket
Using module_utils file ansible_collections/fragmentedpacket/netbox_modules/plugins/module_utils
Using module_utils file ansible_collections/fragmentedpacket/netbox_modules
Using module_utils file ansible_collections/fragmentedpacket/netbox_modules/plugins
Using module_utils file ansible_collections/fragmentedpacket/netbox_modules/plugins/module_utils/netbox_utils
Using module_utils file ansible_collections
Using module_utils file ansible_collections/fragmentedpacket/netbox_modules
Using module_utils file ansible_collections/fragmentedpacket/netbox_modules/plugins/module_utils
Using module_utils file ansible_collections/fragmentedpacket
Using module_utils file ansible_collections/fragmentedpacket/netbox_modules/plugins
Using module_utils file /Users/antoine/.pyenv/versions/3.7.4/lib/python3.7/site-packages/ansible/module_utils/basic.py
Using module_utils file ansible_collections/fragmentedpacket/netbox_modules/plugins/module_utils/netbox_ipam

As soon i add the "netbox_device_interface" the role will crash again.

I'm using ansible 2.8.5, i will try the 2.9

FragmentedPacket commented 4 years ago

My bad for all the back and forth. I missed some important details within your original post.

I tried 2.8.5 and get the same results. I put within the requirements to use Ansible 2.9+. I'm actually surprised that it somewhat works within 2.8.5 as I thought collections was 2.9 or newer.

I think at this point, i'm only worried about supporting 2.9 or newer for the collections.

achrstl commented 4 years ago

Indeed there is no issue with ansible v2.9.0rc3. Thanks for your help, i have a temporary fix in the meantime :)