Code Monkey home page Code Monkey logo

nautobot-plugin-chatops-ansible's Introduction

nautobot-plugin-chatops-ansible

The code in this repository has been migrated to the Nautobot ChatOps Repository as an integration - read more about it in the ChatOps Docs! As of July 2023 this repository has been FROZEN - all development / issues / discussions for this integration are in the Nautobot ChatOps Repository going forward.

A plugin for Nautobot Chatops Plugin

Installation

Build Status

Branch Status
main Build Status
develop Build Status

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

pip install git+https://github.com/nautobot/nautobot-plugin-chatops-ansible.git

This ChatOps Plugin to Nautobot ChatOps Plugin requires the following list of environment variables to be added into the environment.

  • NAUTOBOT_TOWER_URI: Ansible Tower HTTP URI
  • NAUTOBOT_TOWER_USERNAME: Ansible Tower username
  • NAUTOBOT_TOWER_PASSWORD: Ansible Tower password

Once you have updated your environment file, restart both nautobot and nautobot-worker

$ sudo systemctl restart nautobot nautobot-worker

Usage

Command setup

Add a slash command to Slack called /ansible. See the nautobot-chatops installation guide for instructions on adding a slash command to your Slack channel.

You may need to adjust your Access Grants in Nautobot depending on your security requirements.

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.

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>. All commands support the arguments --nautobot-ver and --python-ver if you want to manually define the version of Python and Nautobot to use. Each command also has its own help invoke <command> --help

Local dev environment

  build            Build all docker images.
  debug            Start Nautobot and its dependencies in debug mode.
  destroy          Destroy all containers and volumes.
  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.

Testing

  tests            Run all tests.
  pydocstyle       Run pydocstyle to validate docstring formatting adheres to NTC defined standards.
  bandit           Run bandit to validate basic static code security analysis.
  black            Run black to check that Python files adhere to its style standards.
  unittest         Run Django unit tests for the plugin.

Questions

For any questions or comments, feel free to swing by the Network to Code slack channel (channel #networktocode). Sign up here

nautobot-plugin-chatops-ansible's People

Contributors

dgjustice avatar jvanderaa avatar smk4664 avatar ubajze avatar whitej6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nautobot-plugin-chatops-ansible's Issues

get_job_templates fails with `inventory` error.

Environment

  • Python version: 3.7
  • Nautobot version: 1.3.8
  • nautobot-plugin-chatops: 1.8.0
  • nautobot-plugin-chatops-ansible version: 1.0.3

When running get_job_templates via chatops in a MS team chat client it results in a failure about inventory.

Steps to Reproduce

  1. Execute ansible get_job_templates

Expected Behavior

Return a list of job templates from AWX/Tower.

Observed Behavior

Exception in the chat response about inventory.
An internal error occured 'Inventory'

Full traceback

[2022-07-27 14:33:24,850: ERROR/ForkPoolWorker-2] Task nautobot_chatops.utils.celery_worker_task[80b5175a-81fb-44ca-b8ef-cbaffe6a8d70] raised unexpected: KeyError('inventory')
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 451, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 734, in __protected_call__
    return self.run(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops/utils.py", line 44, in celery_worker_task
    context=context,
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops_ansible/worker.py", line 44, in ansible
    return handle_subcommands("ansible", subcommand, **kwargs)
  File "<decorator-gen-2>", line 2, in handle_subcommands
  File "/usr/local/lib/python3.7/site-packages/prometheus_client/context_managers.py", line 81, in wrapped
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops/workers/__init__.py", line 298, in handle_subcommands
    result = registry[command]["subcommands"][subcommand]["worker"](dispatcher, *params)
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops/workers/__init__.py", line 187, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops_ansible/worker.py", line 196, in get_job_templates
    for entry in job_templates
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops_ansible/worker.py", line 196, in <listcomp>
    for entry in job_templates
KeyError: 'inventory'

Releated to this call:

entry["summary_fields"].get("inventory", {}).get("name", "Ask Inventory on Launch"),

Oddly looking at the api result this code block with the .get() can should work based on what I'm seeing. However, it maybe a better option to be more explict with the call for ask for inventory on launch and look at its bool value. It is available at entry["ask_inventory_on_launch"]

get-inventory - Internal Error

What Happened

Run through testing, when executing /ansible get-inventory returns an internal error:

*An internal error occurred:
'results'*

Rename Repo

The repo indicates that this is a plugin. However, current nomenclature indicates that this is a Nautobot-Chatops-Extension. We should update the repo name to reflect this.

NAUTOBOT_TOWER_URI should auto strip trailing slash

Environment

  • Python version: 3.7
  • Nautobot version: 1.2.5
  • nautobot-plugin-chatops-ansible version: Current

Steps to Reproduce

  1. Setup extension with uri of http://towerorawx.example.com/ with trailing slash
  2. Run ansible chatops command.

Expected Behavior

Expected it to work and auto-detect a trailing slash and remove it.

Observed Behavior

Traceback errors.

Separate out Chat Commands from Tower API functions

Environment

  • Python version: 3.9
  • Nautobot version: 1.0.0
  • nautobot-plugin-chatops-ansible version: 0.1.0

Steps to Reproduce

  1. Look at code
  2. Find everything in one file

Expected Behavior

Expected code to be in separate files for ease of moving around as necessary.

Observed Behavior

Code put together in one file.

Traceback when calling get-job-templates in MS teams.

Environment

  • Python version: 3.7
  • Nautobot version: 1.2.5
  • nautobot-plugin-chatops-ansible version: 1.0.3
  • Running via MS teams.

Steps to Reproduce

  1. run ansible get-job-templates

Expected Behavior

Return the jobs.

Observed Behavior

[2022-04-20 15:05:25,068: ERROR/ForkPoolWorker-1] Task nautobot_chatops.utils.celery_worker_task[e3e7da05-e20b-4835-aaf1-ca9f7977ec29] raised unexpected: KeyError('inventory')
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 451, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 734, in __protected_call__
    return self.run(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops/utils.py", line 44, in celery_worker_task
    context=context,
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops_ansible/worker.py", line 44, in ansible
    return handle_subcommands("ansible", subcommand, **kwargs)
  File "<decorator-gen-2>", line 2, in handle_subcommands
  File "/usr/local/lib/python3.7/site-packages/prometheus_client/context_managers.py", line 81, in wrapped
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops/workers/__init__.py", line 298, in handle_subcommands
    result = registry[command]["subcommands"][subcommand]["worker"](dispatcher, *params)
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops/workers/__init__.py", line 187, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops_ansible/worker.py", line 196, in get_job_templates
    for entry in job_templates
  File "/usr/local/lib/python3.7/site-packages/nautobot_chatops_ansible/worker.py", line 196, in <listcomp>
    for entry in job_templates
KeyError: 'inventory'

Remove default.nix File

Not sure what the file is doing. It does not seem to be referenced anywhere and is not a standard. No mention of what the value or benefit of it is.

Version Updating - Follow ChatOps Upstream

The versioning has to manually be updated within the __init__.py file in a nested folder, on top of updating through poetry. The ChatOps Plugin itself has a newer method that will read from a library with the help of an import from Nautobot. We should mimic that here.

The `/ansible get-jobs` command fails if output includes a job that was started by schedule

Environment

  • Python version: 3.6.1
  • Nautobot version: 1.0.3
  • nautobot-plugin-chatops-ansible version: 1.0.1

Steps to Reproduce

  1. Run the /ansible get-jobs command in Slack. Make sure that you include a job that is started by a schedule.

Expected Behavior

I expected to see the list of jobs.

Observed Behavior

The following is displayed in the output:

*An internal error occurred:
'created_by'* :warning:

The job dict does not have the "created_by" dict because a schedule started it.

Remove Nautobot Plugin files

Proposed Functionality

A chatops extension does not need to initialize as a plugin within Nautobot. I am proposing that we remove the Nautobot Plugin code.

Use Case

A chatops extension builds on nautobot-plugin-chatops, not nautobot itself.

Move Pylint Settings

To follow our standard dev environment data the pylint settings should be in pyproject.toml

Worker import method depreciated

Proposed Functionality

Change from nautobot_chatops.workers.base import subcommand_of, handle_subcommands
to from nautobot_chatops.workers import subcommand_of, handle_subcommands.

Use Case

The nautobot_chatops.workers.base is listed as obsolete and will be deprecated.

The `/ansible run-job-template` command throws an error if started without the template name

Environment

  • Python version: 3.6.1
  • Nautobot version: 1.0.3
  • nautobot-plugin-chatops-ansible version: 1.0.1

Steps to Reproduce

  1. Run the command /ansible run-job-template.

Expected Behavior

I expect to get a list of job templates and an option to select a template from the list.

Observed Behavior

The following traceback in displayed in the debug output:

worker_1    | 12:38:35 ERROR Traceback (most recent call last):
worker_1    |   File "/usr/local/lib/python3.6/site-packages/rq/worker.py", line 1013, in perform_job
worker_1    |     rv = job.perform()
worker_1    |   File "/usr/local/lib/python3.6/site-packages/rq/job.py", line 709, in perform
worker_1    |     self._result = self._execute()
worker_1    |   File "/usr/local/lib/python3.6/site-packages/rq/job.py", line 732, in _execute
worker_1    |     result = self.func(*self.args, **self.kwargs)
worker_1    |   File "/usr/local/lib/python3.6/site-packages/nautobot_chatops_ansible/worker.py", line 43, in ansible
worker_1    |     return handle_subcommands("ansible", subcommand, **kwargs)
worker_1    |   File "<decorator-gen-1>", line 2, in handle_subcommands
worker_1    |   File "/usr/local/lib/python3.6/site-packages/prometheus_client/context_managers.py", line 66, in wrapped
worker_1    |     return func(*args, **kwargs)
worker_1    |   File "/usr/local/lib/python3.6/site-packages/nautobot_chatops/workers/__init__.py", line 298, in handle_subcommands
worker_1    |     result = registry[command]["subcommands"][subcommand]["worker"](dispatcher, *params)
worker_1    |   File "/usr/local/lib/python3.6/site-packages/nautobot_chatops/workers/__init__.py", line 187, in wrapper
worker_1    |     return func(*args, **kwargs)
worker_1    |   File "/usr/local/lib/python3.6/site-packages/nautobot_chatops_ansible/worker.py", line 235, in run_job_template
worker_1    |     return prompt_for_job_template(dispatcher, "ansible run-job-template")
worker_1    |   File "/usr/local/lib/python3.6/site-packages/nautobot_chatops_ansible/worker.py", line 33, in prompt_for_job_template
worker_1    |     job_templates = data["results"]
worker_1    | TypeError: list indices must be integers or slices, not str

DepreationWarning with one of the imports/methods in use.

Environment

  • Python version: 3.7
  • Nautobot version: 1.2.5
  • nautobot-plugin-chatops-ansible version: current

Steps to Reproduce

  1. Install app
  2. Run nautobot and tail the logs

Expected Behavior

No deprecation warnings.

Observed Behavior

nautobot_2 | /usr/local/lib/python3.7/site-packages/nautobot_chatops/workers/base.py:15: DeprecationWarning: Importing from `nautobot_chatops.workers.base` has been deprecated, please use `nautobot_chatops.workers`
nautobot_2 | for `subcommand_of` and `handle_subcommands` or `nautobot_chatops.utils` for `create_command_log`
nautobot_2 | DeprecationWarning,

Looks like this line.

from nautobot_chatops.workers.base import subcommand_of, handle_subcommands

Commands fail with "Expecting value: line 5 column 1 (char 4)"

Environment

  • Python version: 3.7.9
  • Nautobot version: 1.0.2
  • nautobot-plugin-chatops-ansible version: develop

Steps to Reproduce

  1. Setup with Ansible Tower
  2. Add to Slack
  3. Run command /ansible get-dashboard

Expected Behavior

Command succeeds and returns data.

Observed Behavior

⚠️ An internal error occurred:
Expecting value: line 5 column 1 (char 4)
⚠️

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.