Skip to main content

Nautobot App that provides Ansible filters within Nautobot.

Project description

Ansible Filters

A plugin for Nautobot that incorporates Ansible filters via the jinj2_ansible_filters package.

Installation

The plugin is available as a Python package in pypi and can be installed with pip.

pip install nautobot-ansible-filters

The plugin is compatible with Nautobot 1.2.0 and higher

To ensure Ansible Filters is automatically re-installed during future upgrades, create a file named local_requirements.txt (if not already existing) in the Nautobot root directory (alongside requirements.txt) and list the nautobot-ansible-filters package:

# echo nautobot-ansible-filters >> local_requirements.txt

Once installed, the plugin needs to be enabled in your nautobot_config.py

# In your nautobot_config.py
PLUGINS = ["nautobot_ansible_filters"]

Usage

These Jinja filters will be available using the Ansible builtin FQCN (Fully Qualified Collection Name). For example, regex_replace will be available via ansible.builtin.regex_replace.

regex_replace

We're looking to create a computed field on a site to replace any other airport code (or really any first three characters of a string) with MSP.

Here is what the computed field would look like on a site called DEN01.

site

Contributing

Pull requests are welcomed and automatically built and tested against multiple version of Python and multiple version of Nautobot through TravisCI.

The project is packaged with a light development environment based on docker-compose to help with the local development of the project and to run the tests within TravisCI.

The project is following Network to Code software development guideline and is leveraging:

  • Black, Pylint, Bandit and pydocstyle for Python linting and formatting.
  • Django unit test to ensure the plugin is working properly.

Development Environment

The development environment can be used in 2 ways. First, with a local poetry environment if you wish to develop outside of Docker with the caveat of using external services provided by Docker for PostgresQL and Redis. Second, all services are spun up using Docker and a local mount so you can develop locally, but Nautobot is spun up within the Docker container.

Invoke

The PyInvoke library is used to provide some helper commands based on the environment. There are a few configuration parameters which can be passed to PyInvoke to override the default configuration:

  • nautobot_ver: the version of Nautobot to use as a base for any built docker containers (default: latest)
  • project_name: the default docker compose project name (default: ansible_filters)
  • python_ver: the version of Python to use as a base for any built docker containers (default: 3.7)
  • local: a boolean flag indicating if invoke tasks should be run on the host or inside the docker containers (default: False, commands will be run in docker containers)
  • compose_dir: the full path to a directory containing the project compose files
  • compose_files: a list of compose files applied in order (see Multiple Compose files for more information)

Using PyInvoke these configuration options can be overridden using several methods. Perhaps the simplest is simply setting an environment variable INVOKE_ANSIBLE_FILTERS_VARIABLE_NAME where VARIABLE_NAME is the variable you are trying to override. The only exception is compose_files, because it is a list it must be overridden in a yaml file. There is an example invoke.yml (invoke.example.yml) in this directory which can be used as a starting point.

Docker Development Environment

This project is managed by Python Poetry and has a few requirements to setup your development environment:

  1. Install Poetry, see the Poetry Documentation for your operating system.
  2. Install Docker, see the Docker documentation for your operating system.

Once you have Poetry and Docker installed you can run the following commands to install all other development dependencies in an isolated python virtual environment:

poetry shell
poetry install
invoke build start

Nautobot server can now be accessed at http://localhost:8080.

To either stop or destroy the development environment use the following options.

  • invoke stop - Stop the containers, but keep all underlying systems intact
  • invoke destroy - Stop and remove all containers, volumes, etc. (This results in data loss due to the volume being deleted)

CLI Helper Commands

The project is coming with a CLI helper based on invoke to help setup the development environment. The commands are listed below in 3 categories dev environment, utility and testing.

Each command can be executed with invoke <command>. Environment variables INVOKE_ANSIBLE_FILTERS_PYTHON_VER and INVOKE_ANSIBLE_FILTERS_NAUTOBOT_VER may be specified to override the default versions. Each command also has its own help invoke <command> --help

Docker dev environment

  build            Build all docker images.
  debug            Start Nautobot and its dependencies in debug mode.
  destroy          Destroy all containers and volumes.
  restart          Restart Nautobot and its dependencies.
  start            Start Nautobot and its dependencies in detached mode.
  stop             Stop Nautobot and its dependencies.

Utility

  cli              Launch a bash shell inside the running Nautobot container.
  create-user      Create a new user in django (default: admin), will prompt for password.
  makemigrations   Run Make Migration in Django.
  nbshell          Launch a nbshell session.
  shell-plus       Launch a shell_plus session, which uses iPython and automatically imports all models.

Testing

  bandit           Run bandit to validate basic static code security analysis.
  black            Run black to check that Python files adhere to its style standards.
  flake8           This will run flake8 for the specified name and Python version.
  pydocstyle       Run pydocstyle to validate docstring formatting adheres to NTC defined standards.
  pylint           Run pylint code analysis.
  tests            Run all tests for this plugin.
  unittest         Run Django unit tests for the plugin.

Questions

For any questions or comments, please check the FAQ first and feel free to swing by the Network to Code slack channel (channel #nautobot). Sign up here

Screenshots

TODO

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nautobot_ansible_filters-2.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

nautobot_ansible_filters-2.0.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file nautobot_ansible_filters-2.0.0.tar.gz.

File metadata

File hashes

Hashes for nautobot_ansible_filters-2.0.0.tar.gz
Algorithm Hash digest
SHA256 dca250de4e049f99a23e67de0d27e5fa8a55e7041157238e3943d1f2e617a206
MD5 dbc413758f785d5567bf5ede17fef3e3
BLAKE2b-256 0e103d547f48b53822419327f18049f968d8f6259ad41ffa81743b137c3c7feb

See more details on using hashes here.

File details

Details for the file nautobot_ansible_filters-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nautobot_ansible_filters-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27b9edeb3672976b276ee62cdfd66fe199907b13c8f27436d3a2fd5d5718e189
MD5 e63574435c601c537bfd2efe4234096c
BLAKE2b-256 77fc7736da499a6d30255c5869486deee81969daa51bc41d5dd8d4f79804bac5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page