# Ansible Filters
A plugin for [Nautobot](https://github.com/nautobot/nautobot) that incorporates Ansible filters via the [jinj2_ansible_filters](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters) package.
## Installation
The plugin is available as a Python package in pypi and can be installed with pip.
```shell
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:
```no-highlight
# echo nautobot-ansible-filters >> local_requirements.txt
```
Once installed, the plugin needs to be enabled in your `nautobot_config.py`
```python
# 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](docs/images/regex_replace.png)
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](docs/images/regex_replace_site.png)
## 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](http://www.pyinvoke.org/) 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](https://docs.docker.com/compose/extends/#multiple-compose-files) for more information)
Using **PyInvoke** these configuration options can be overridden using [several methods](http://docs.pyinvoke.org/en/stable/concepts/configuration.html). 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](https://python-poetry.org/) and has a few requirements to setup your development environment:
1. Install Poetry, see the [Poetry Documentation](https://python-poetry.org/docs/#installation) for your operating system.
2. Install Docker, see the [Docker documentation](https://docs.docker.com/get-docker/) 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:
```shell
poetry shell
poetry install
invoke build start
```
Nautobot server can now be accessed at [http://localhost:8080](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](http://www.pyinvoke.org/) 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
```no-highlight
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
```no-highlight
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
```no-highlight
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](FAQ.md) first and feel free to swing by the [Network to Code slack channel](https://networktocode.slack.com/) (channel #nautobot).
Sign up [here](http://slack.networktocode.com/)
## Screenshots
TODO
Raw data
{
"_id": null,
"home_page": "https://github.com/FragmentedPacket/nautobot-plugin-ansible-filters",
"name": "nautobot-ansible-filters",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.12,>=3.8",
"maintainer_email": null,
"keywords": "nautobot, nautobot-plugin",
"author": "Mikhail Yohman",
"author_email": "mikhail.yohman@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d8/bd/37b2668000c98584fdb72d195ddd0a22368ced8f44a5cb5cd46b561a863e/nautobot_ansible_filters-2.0.2.tar.gz",
"platform": null,
"description": "# Ansible Filters\n\nA plugin for [Nautobot](https://github.com/nautobot/nautobot) that incorporates Ansible filters via the [jinj2_ansible_filters](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters) package.\n\n## Installation\n\nThe plugin is available as a Python package in pypi and can be installed with pip.\n\n```shell\npip install nautobot-ansible-filters\n```\n\n> The plugin is compatible with Nautobot 1.2.0 and higher\n\nTo 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:\n\n```no-highlight\n# echo nautobot-ansible-filters >> local_requirements.txt\n```\n\nOnce installed, the plugin needs to be enabled in your `nautobot_config.py`\n\n```python\n# In your nautobot_config.py\nPLUGINS = [\"nautobot_ansible_filters\"]\n```\n\n## Usage\n\nThese 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`.\n\n![regex_replace](docs/images/regex_replace.png)\n\nWe'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**.\n\nHere is what the computed field would look like on a site called **DEN01**.\n\n![site](docs/images/regex_replace_site.png)\n\n## Contributing\n\nPull requests are welcomed and automatically built and tested against multiple version of Python and multiple version of Nautobot through TravisCI.\n\nThe 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.\n\nThe project is following Network to Code software development guideline and is leveraging:\n\n- Black, Pylint, Bandit and pydocstyle for Python linting and formatting.\n- Django unit test to ensure the plugin is working properly.\n\n### Development Environment\n\nThe 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.\n\n#### Invoke\n\nThe [PyInvoke](http://www.pyinvoke.org/) 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:\n\n- `nautobot_ver`: the version of Nautobot to use as a base for any built docker containers (default: latest)\n- `project_name`: the default docker compose project name (default: ansible_filters)\n- `python_ver`: the version of Python to use as a base for any built docker containers (default: 3.7)\n- `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)\n- `compose_dir`: the full path to a directory containing the project compose files\n- `compose_files`: a list of compose files applied in order (see [Multiple Compose files](https://docs.docker.com/compose/extends/#multiple-compose-files) for more information)\n\nUsing **PyInvoke** these configuration options can be overridden using [several methods](http://docs.pyinvoke.org/en/stable/concepts/configuration.html). 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.\n\n#### Docker Development Environment\n\nThis project is managed by [Python Poetry](https://python-poetry.org/) and has a few requirements to setup your development environment:\n\n1. Install Poetry, see the [Poetry Documentation](https://python-poetry.org/docs/#installation) for your operating system.\n2. Install Docker, see the [Docker documentation](https://docs.docker.com/get-docker/) for your operating system.\n\nOnce you have Poetry and Docker installed you can run the following commands to install all other development dependencies in an isolated python virtual environment:\n\n```shell\npoetry shell\npoetry install\ninvoke build start\n```\n\nNautobot server can now be accessed at [http://localhost:8080](http://localhost:8080).\n\nTo either stop or destroy the development environment use the following options.\n\n- **invoke stop** - Stop the containers, but keep all underlying systems intact\n- **invoke destroy** - Stop and remove all containers, volumes, etc. (This results in data loss due to the volume being deleted)\n\n### CLI Helper Commands\n\nThe project is coming with a CLI helper based on [invoke](http://www.pyinvoke.org/) to help setup the development environment. The commands are listed below in 3 categories `dev environment`, `utility` and `testing`.\n\nEach 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`\n\n#### Docker dev environment\n\n```no-highlight\n build Build all docker images.\n debug Start Nautobot and its dependencies in debug mode.\n destroy Destroy all containers and volumes.\n restart Restart Nautobot and its dependencies.\n start Start Nautobot and its dependencies in detached mode.\n stop Stop Nautobot and its dependencies.\n```\n\n#### Utility\n\n```no-highlight\n cli Launch a bash shell inside the running Nautobot container.\n create-user Create a new user in django (default: admin), will prompt for password.\n makemigrations Run Make Migration in Django.\n nbshell Launch a nbshell session.\n shell-plus Launch a shell_plus session, which uses iPython and automatically imports all models.\n```\n\n#### Testing\n\n```no-highlight\n bandit Run bandit to validate basic static code security analysis.\n black Run black to check that Python files adhere to its style standards.\n flake8 This will run flake8 for the specified name and Python version.\n pydocstyle Run pydocstyle to validate docstring formatting adheres to NTC defined standards.\n pylint Run pylint code analysis.\n tests Run all tests for this plugin.\n unittest Run Django unit tests for the plugin.\n```\n\n## Questions\n\nFor any questions or comments, please check the [FAQ](FAQ.md) first and feel free to swing by the [Network to Code slack channel](https://networktocode.slack.com/) (channel #nautobot).\nSign up [here](http://slack.networktocode.com/)\n\n## Screenshots\n\nTODO\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Nautobot App that provides Ansible filters within Nautobot.",
"version": "2.0.2",
"project_urls": {
"Homepage": "https://github.com/FragmentedPacket/nautobot-plugin-ansible-filters",
"Repository": "https://github.com/FragmentedPacket/nautobot-plugin-ansible-filters"
},
"split_keywords": [
"nautobot",
" nautobot-plugin"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fd1f473778cf54c3e4297c53c54fa0c60870275c861c1b053edbe2367941a5ea",
"md5": "49cf273b1bf583e52a35392c64796adc",
"sha256": "8ef6de864bfab3887e0f12244796fa1b20692e4697361f16733d7744f1cd0831"
},
"downloads": -1,
"filename": "nautobot_ansible_filters-2.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "49cf273b1bf583e52a35392c64796adc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.12,>=3.8",
"size": 9346,
"upload_time": "2024-06-19T15:41:05",
"upload_time_iso_8601": "2024-06-19T15:41:05.584965Z",
"url": "https://files.pythonhosted.org/packages/fd/1f/473778cf54c3e4297c53c54fa0c60870275c861c1b053edbe2367941a5ea/nautobot_ansible_filters-2.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d8bd37b2668000c98584fdb72d195ddd0a22368ced8f44a5cb5cd46b561a863e",
"md5": "ae82cfa7bea39277fa8b9f123a74ec26",
"sha256": "b5f1432904843fd02a3b769b58c58b3b61804fb28b205e4a07997be611b24e72"
},
"downloads": -1,
"filename": "nautobot_ansible_filters-2.0.2.tar.gz",
"has_sig": false,
"md5_digest": "ae82cfa7bea39277fa8b9f123a74ec26",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.12,>=3.8",
"size": 6090,
"upload_time": "2024-06-19T15:41:10",
"upload_time_iso_8601": "2024-06-19T15:41:10.269440Z",
"url": "https://files.pythonhosted.org/packages/d8/bd/37b2668000c98584fdb72d195ddd0a22368ced8f44a5cb5cd46b561a863e/nautobot_ansible_filters-2.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-19 15:41:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "FragmentedPacket",
"github_project": "nautobot-plugin-ansible-filters",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "nautobot-ansible-filters"
}