Git Product home page Git Product logo

ansible-role-netbox's Introduction

Ansible Role: Netbox

Netbox CI Netbox Ansible Galaxy Ansible Quality Score Version

Installs, configures and maintains NetBox on a variety of popular Linux distributions.

Contents

General Information

This role manages the installation and configuration of NetBox. It does not provide PostgreSQL or Redis services that are required dependencies of the application. Those tasks are intentionally left to allow the user to manage those services within their own roles and playbooks. Please see the EXAMPLE playbook for details about how to manage those services.

Releases are only issued when necessary to support changes in NetBox. This role is continuously tested on new versions of NetBox. Please see the GitHub repo for the latest compatability information.

Supported Platforms

Tested on the following platforms:

  • Amazon Linux 2
  • CentOS 8
  • Debian Bookworm
  • Debian Bullseye
  • Fedora Linux 37
  • Rocky Linux 8 / Red Hat Enterprise Linux (RHEL) 8.2+
  • Rocky Linux 9 / Red Hat Enterprise Linux (RHEL) 9.3+
  • Ubuntu 20.04
  • Ubuntu 22.04

This role will require root access (via sudo) to manage system dependencies and actions on behalf of netbox.

Supports NetBox versions >=3.5.9

Role variables

Minimum required variables assuming localhost PostgreSQL and Redis services are available:

netbox_db_username: netbox
netbox_db_password: netbox
netbox_secret_key: "lnvRn_5Bypl8hBV4mMwgsMuHxr6uZvGwJyDqB7fcKqo"

If the netbox_secret_key is omitted a new one will be automatically generated on each playbook run.

See defaults/main.yml for a complete list of defaults and configurable options.

Note: Version 3.1+ introduced Dynamic Configuration Settings. These configuration options may still be written to configuration.py preventing modification via the UI. However, by default, this role always omits these parameters unless netbox_override_dynamic_config is set to True. See defaults/main.yml#L82 for details.

User accounts

The following variables can be defined to create users during initial installation only:

netbox_superusers:
  - username: admin
    password: admin
    email: [email protected]

Each user requires a username, password and email address defined. The role will attempt to create the defined users only once during initial installation. If netbox_superusers is not defined, no users are created and the manual user creation process documented by Netbox can be used instead.

External Authentication

See the wiki for information about available external authentication methods.

Plugins

Netbox plugins that are pip modules can be installed and configured by setting the netbox_plugins list variable. Below is an example for the Netbox BGP plugin.

netbox_plugins:
  - name: netbox_bgp    # Plugin name
    pip: netbox-bgp     # Pip module name
    config:             # Plugin configuration
      device_ext_page: left
      asdot: True

Removing Plugins

To remove a plugin, an absent state can be assigned to the netbox_plugins entry:

netbox_plugins:
  - name: netbox_bgp    # Plugin name
    pip: netbox-bgp     # Pip module name
    state: absent

Note that it may be necessary to remove database tables that were installed as part of a plugin. This role does not manage database tables that may have been created as part of a plugin. Please see the documentation for more information on table management.

Version locking

A specific version of netbox can be configured using the variable:

netbox_version_tag: v3.0.9

This tag should match the Github tag name for the release to be installed. It will ensure that a specific target is maintained. If not set, each run will attempt to find the latest release version to install.

NOTE: A version tag should be set for most environments to ensure a known installation is maintained.

Another option is to deploy from a specifc branch and optionally a specific commit SHA

netbox_install_method: git
netbox_git_branch: master
netbox_git_sha: 8f1acb700d72467ffe7ae5c8502422a1eac0693d # optional

Dependencies

No Ansible dependencies. The application requires Redis and Postgres.

Example Playbook

See EXAMPLE for a complete playbook example.

Contributing

Contributions are encouraged. Please see CONTRIBUTING for details.

ansible-role-netbox's People

Contributors

duviful avatar jvoss avatar markh0338 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ansible-role-netbox's Issues

Missing packages when installing on Fedora

I used this role successfully on Fedora 37 (see #57 ).

I had to add some packages to get it working, see this playbook:

- name: 'Install netbox'
  hosts: 'all'
  gather_facts: true
  become: true

  pre_tasks:

    - name: Install cronie
      ansible.builtin.package:
        name: cronie
        state: present

    - name: Install acl
      ansible.builtin.package:
        name: acl
        state: present

    - name: Install python3-django
      ansible.builtin.package:
        name: python3-django
        state: present

  roles:
    - role: 'jvoss.netbox'

If desired I can add a PR to make the role install those packages on Fedora.

Release action fails

GitHub Release action fails to run properly. Publish works when performing the same actions locally.

  1. Install Ansible base: pip install ansible-base
  2. Publish to Galaxy: ansible-galaxy role import --api-key *** $(echo jvoss/ansible-role-netbox | cut -d/ -f1) $(echo jvoss/ansible-role-netbox | cut -d/ -f2)
Run ansible-galaxy role import --api-key *** $(echo jvoss/ansible-role-netbox | cut -d/ -f1) $(echo jvoss/ansible-role-netbox | cut -d/ -f2)
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.1/x64/bin/ansible-galaxy", line 62, in <module>
    import ansible.constants as C
  File "/opt/hostedtoolcache/Python/3.12.1/x64/lib/python3.12/site-packages/ansible/constants.py", line 15, in <module>
    from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_value
  File "/opt/hostedtoolcache/Python/3.12.1/x64/lib/python3.12/site-packages/ansible/config/manager.py", line 29, in <module>
    from ansible.module_utils.six.moves import configparser
ModuleNotFoundError: No module named 'ansible.module_utils.six.moves'
Error: Process completed with exit code 1.

Add support to plugins

Hello dear sir.
it would be nice to add custom plugins to local_requirements.txt and install them automatically.

a task in the file configure.yml similar to this one can do the job:

- name: configure | add the custom plugins local_requirements.txt
  ansible.builtin.lineinfile:
    path: "{{ netbox_current_path }}/local_requirements.txt"
    line: "{{ item.name }}"
    regexp: "^{{ item.name }}"
    owner: "{{ netbox_user }}"
    mode: '0644'
    create: yes
  with_items: "{{ netbox_plugins }}"

I'm using the already present variable netbox_plugins to generate the list of names to be added to the local_requirements.txt

I might open a PR but I suspect you are already working on something like this.
let me know.

Best

Add support for Debian Bookworm

Add the following to support Debian bookworm:

vars/Debian-12.yml:

---
__python_version: "3.11"
__python_packages:
    - "python{{ python_version | default(__python_version) }}"
    - "python3-pip"
    - "python{{ python_version | default(__python_version) }}-venv"
    - "python{{ python_version | default(__python_version) }}-dev"

Ansible fails to write `configuration.py`

Ansible bugs when writing configuration.py in Debian Bookworm.

TASK [jvoss.netbox : configure | write configuration.py] *************************************************
fatal: [netbox]: FAILED! => 
  msg: |-
    Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chmod: invalid mode: ‘A+user:netbox:rx:allow’
    Try 'chmod --help' for more information.
    }). For information on working around this, see https://docs.ansible.com/ansible-core/2.15/playbook_guide/playbooks_privilege_escalation.html#risks-of-becoming-an-unprivileged-user#risks-of-becoming-an-unprivileged-user

Remove the following lines:

become: yes
become_user: "{{ netbox_user }}"

become: yes
become_user: "{{ netbox_user }}"

become: yes
become_user: "{{ netbox_user }}"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.