unicolet / ansible_network_example

Implementation from scratch of an ansible network module and resource

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Example implementation of an Ansible network module and resource

Implementation of a fake Ansible network module and connection resource, used to learn how it all ties together.

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. Contact

About The Project

This repository contains a custom module and a connection resource for a fake network device called unicolet.

As of now the module does not realy use the network resource (no actual network call is made), however it shouws how the two interact. This is illustrated by the get_device_info() call in the module, which calls the corresponding function in the resource.

(back to top)

Built With

  • Python 3
  • Ansible 7.2.0

(back to top)

Getting Started

Create a pipenv, then install the required packages with pipenv install. Once you have a working ansible installation you'll need to install additional ansible modules:

ansible-galaxy collection install ansible.netcommon:4.1.0

Running the module

Run ansible as follows:

ANSIBLE_CONFIG=./ansible.cfg ansible -i inventory unicolet -m unicolet_ping

if all goes well you should see an output like the following:

PLAY [Ansible Ad-Hoc] *****************************************************************

TASK [unicolet_ping] ******************************************************************
ok: [unicolet]

PLAY RECAP ****************************************************************************
unicolet                   : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Play around with the python code and see how it can break, for example if you rename the get_device_info function in the network resource.

Installation

It is not possible to install or use this module as it's not really meant to work. Maybe in the future there will be a full collection that can be installed through ansible-galaxy.

(back to top)

Contributing

File an issue and preferrably a pull request. I'm not actively looking for contributions at this time so delays in answering are to be expected.

(back to top)

Contact

@unicolet

(back to top)

About

Implementation from scratch of an ansible network module and resource

License:MIT License


Languages

Language:Python 100.0%