smolz / ansible_modules

Netbox modules for Ansible using Ansible Collections

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Code style: black Release

Netbox modules for Ansible using Ansible Collections

We have moved this collection to a different namespace and collection name on Ansible Galaxy. The new versions will be at netbox.netbox.

To keep the code simple, we only officially support the two latesst releases of Netbox and don't guarantee backwards compatibility beyond that. We do try and keep these breaking changes to a minimum, but sometimes changes to NetBox's API cause us to have to make breaking changes.

Requirements

  • NetBox 2.5+ or the two latest NetBox releases
  • pynetbox 4.2.5+
  • Python 3.6+
  • Ansible 2.9+

Existing Modules

  • netbox_aggregate
  • netbox_circuit
  • netbox_circuit_termination
  • netbox_circuit_type
  • netbox_cluster
  • netbox_cluster_group
  • netbox_cluster_type
  • netbox_device_bay
  • netbox_device_interface
  • netbox_device_role
  • netbox_device_type
  • netbox_device
  • netbox_inventory_item
  • netbox_ip_address
  • netbox_ipam_role
  • netbox_manufacturer
  • netbox_platform
  • netbox_prefix
  • netbox_provider
  • netbox_rack_group
  • netbox_rack_role
  • netbox_rack
  • netbox_region
  • netbox_rir
  • netbox_site
  • netbox_service
  • netbox_tenant_group
  • netbox_tenant
  • netbox_virtual_machine
  • netbox_vm_interface
  • netbox_vlan_group
  • netbox_vlan
  • netbox_vrf

Netbox Plugins

  • netbox lookup plugin
  • netbox inventory plugin (0.1.5)

How to Use

  • Install via Galaxy
    • ansible-galaxy collection install netbox.netbox
  • Install via source
    • git clone git@github.com:netbox-community/ansible_modules.git
    • cd ansible_modules
    • ansible-galaxy collection build .
    • ansible-galaxy collection install netbox-netbox-X.X.X.tar.gz
      • Can add -p to provide a different path other than the default path, but it must be within your ansible.cfg or provided via an environment variable.

Example playbooks

Using the collections at the play level

- name: "Test Netbox modules"
  connection: local
  hosts: localhost
  gather_facts: False
  collections:
    - netbox.netbox

  tasks:
    - name: Create device within Netbox with only required information
      netbox_device:
        netbox_url: http://netbox-demo.org:32768
        netbox_token: 0123456789abcdef0123456789abcdef01234567
        data:
          name: Test66
          device_type: Cisco Test
          device_role: Core Switch
          site: Test Site
          status: Staged
          state: present

Using the collections at the task level

- name: "Test Netbox modules"
  connection: local
  hosts: localhost
  gather_facts: False

  tasks:
    - name: Create device within Netbox with only required information
      netbox.netbox.netbox_device:
        netbox_url: http://netbox-demo.org:32768
        netbox_token: 0123456789abcdef0123456789abcdef01234567
        data:
          name: Test66
          device_type: Cisco Test
          device_role: Core Switch
          site: Test Site
          status: Staged
          state: present

Using the collections in a role's task files

---
- name: Create device within Netbox with only required information
  netbox.netbox.netbox_device:
    netbox_url: http://netbox-demo.org:32768
    netbox_token: 0123456789abcdef0123456789abcdef01234567
    data:
      name: Test66
      device_type: Cisco Test
      device_role: Core Switch
      site: Test Site
      status: Staged
      state: present

OR

---
- name: Create device within Netbox with only required information
  collections:
    - netbox.netbox
  netbox_device:
    netbox_url: http://netbox-demo.org:32768
    netbox_token: 0123456789abcdef0123456789abcdef01234567
    data:
      name: Test66
      device_type: Cisco Test
      device_role: Core Switch
      site: Test Site
      status: Staged
      state: present

Using the collections lookup plugin at the task level

- name: "TEST NETBOX_LOOKUP"
  connection: local
  hosts: localhost
  gather_facts: False

  tasks:
    - name: "NETBOX_LOOKUP 1: Lookup returns exactly two sites"
      assert:
        that: "{{ query_result|count }} == 3"
      vars:
        query_result: "{{ query('nb_lookup', 'sites', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}"

How to Contribute

Please read Contributing

About

Netbox modules for Ansible using Ansible Collections

License:GNU General Public License v3.0


Languages

Language:Python 100.0%