Package: nautobot-ansible-filters
Ansible FiltersA plugin forNautobotthat incorporates Ansible filters via thejinj2_ansible_filterspackage.InstallationThe plugin is available as a Python package in pypi and can be installed with pip.pipinstallnautobot-ansible-filtersThe plugin is compatible with Nautobot 1.2.0 and higherTo ensure Ansible Filters is automatically re-installed during future upgrades, create a file namedlocal_requirements.txt(if not already existing) in the Nautobot root directory (alongsiderequirements.txt) and list thenautobot-ansible-filterspackage:# echo nautobot-ansible-filters >> local_requirements.txtOnce installed, the plugin needs to be enabled in yournautobot_config.py# In your nautobot_config.pyPLUGINS=["nautobot_ansible_filters"]UsageThese Jinja filters will be available using the AnsiblebuiltinFQCN (Fully Qualified Collection Name). For example,regex_replacewill be available viaansible.builtin.regex_replace.We're looking to create a computed field on asiteto replace any other airport code (or really any first three characters of a string) withMSP.Here is what the computed field would look like on a site calledDEN01.ContributingPull 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 ondocker-composeto 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 EnvironmentThe 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.InvokeThePyInvokelibrary 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 filescompose_files: a list of compose files applied in order (seeMultiple Compose filesfor more information)UsingPyInvokethese configuration options can be overridden usingseveral methods. Perhaps the simplest is simply setting an environment variableINVOKE_ANSIBLE_FILTERS_VARIABLE_NAMEwhereVARIABLE_NAMEis the variable you are trying to override. The only exception iscompose_files, because it is a list it must be overridden in a yaml file. There is an exampleinvoke.yml(invoke.example.yml) in this directory which can be used as a starting point.Docker Development EnvironmentThis project is managed byPython Poetryand has a few requirements to setup your development environment:Install Poetry, see thePoetry Documentationfor your operating system.Install Docker, see theDocker documentationfor 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:poetryshell
poetryinstall
invokebuildstartNautobot server can now be accessed athttp://localhost:8080.To either stop or destroy the development environment use the following options.invoke stop- Stop the containers, but keep all underlying systems intactinvoke destroy- Stop and remove all containers, volumes, etc. (This results in data loss due to the volume being deleted)CLI Helper CommandsThe project is coming with a CLI helper based oninvoketo help setup the development environment. The commands are listed below in 3 categoriesdev environment,utilityandtesting.Each command can be executed withinvoke <command>. Environment variablesINVOKE_ANSIBLE_FILTERS_PYTHON_VERandINVOKE_ANSIBLE_FILTERS_NAUTOBOT_VERmay be specified to override the default versions. Each command also has its own helpinvoke <command> --helpDocker dev environmentbuild            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.Utilitycli              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.Testingbandit           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.QuestionsFor any questions or comments, please check theFAQfirst and feel free to swing by theNetwork to Code slack channel(channel #nautobot).
Sign uphereScreenshotsTODO