Implementation of a fake Ansible network module and connection resource, used to learn how it all ties together.
Table of Contents
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.
- Python 3
- Ansible 7.2.0
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
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.
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
.
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.