nautobot-ansible-filters


Namenautobot-ansible-filters JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttps://github.com/FragmentedPacket/nautobot-plugin-ansible-filters
SummaryNautobot App that provides Ansible filters within Nautobot.
upload_time2024-02-06 05:19:34
maintainer
docs_urlNone
authorMikhail Yohman
requires_python>=3.8,<3.12
license
keywords nautobot nautobot-plugin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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": "",
    "docs_url": null,
    "requires_python": ">=3.8,<3.12",
    "maintainer_email": "",
    "keywords": "nautobot,nautobot-plugin",
    "author": "Mikhail Yohman",
    "author_email": "mikhail.yohman@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/12/95/c44de122b1ebd2e1903016fff31fecf40138fedbb3259de0cdc3d34e1180/nautobot_ansible_filters-2.0.1.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": "",
    "summary": "Nautobot App that provides Ansible filters within Nautobot.",
    "version": "2.0.1",
    "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": "5a7f70e68b57f4d6228eb0e3f52a8820ec967f68ed2b67183eccb7a756b3e160",
                "md5": "79bcc972a4de238a690f73c4a8269031",
                "sha256": "6d3d2dcecedbaad87edb704b4cec6b582b5ba364105b75a2a387bc3d497dff82"
            },
            "downloads": -1,
            "filename": "nautobot_ansible_filters-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "79bcc972a4de238a690f73c4a8269031",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<3.12",
            "size": 9345,
            "upload_time": "2024-02-06T05:19:32",
            "upload_time_iso_8601": "2024-02-06T05:19:32.499745Z",
            "url": "https://files.pythonhosted.org/packages/5a/7f/70e68b57f4d6228eb0e3f52a8820ec967f68ed2b67183eccb7a756b3e160/nautobot_ansible_filters-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1295c44de122b1ebd2e1903016fff31fecf40138fedbb3259de0cdc3d34e1180",
                "md5": "a0299841eda8ea263e1ca968267dc495",
                "sha256": "0ea30aa28325e1feee746f14f1f28f45cd86ac1ad6901a139a54dab6297c7a7c"
            },
            "downloads": -1,
            "filename": "nautobot_ansible_filters-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a0299841eda8ea263e1ca968267dc495",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<3.12",
            "size": 6067,
            "upload_time": "2024-02-06T05:19:34",
            "upload_time_iso_8601": "2024-02-06T05:19:34.129902Z",
            "url": "https://files.pythonhosted.org/packages/12/95/c44de122b1ebd2e1903016fff31fecf40138fedbb3259de0cdc3d34e1180/nautobot_ansible_filters-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-06 05:19:34",
    "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"
}
        
Elapsed time: 0.17299s