- 10 Jan 2025
-
DarkLight
-
PDF
ZPE Cloud
- Updated on 10 Jan 2025
-
DarkLight
-
PDF
Steps to Create a Dynamic Inventory
To create and manage device inventory via plugin, several steps are required. This guide covers the Nodegrid and ZPE Cloud plugin.
Related Reading: ZPE Cloud Automation with Ansible
Prerequisites
Verify you are using the correct ansible and python binaries. Depending on your setup in Automation Gateway, it will change how you perform a few of the steps below.
First, if you are using the default python3
bin location at /usr/local/bin/python3
or /usr/bin/python3
, ensure the location of the python3
binary matches your path:
which python3
Next, if you are using a Python VENV (virtual environment), you will want to source the VENV first:
source /opt/automation-gateway/.venv/bin/activate
Last, you will want to use the binary location of the Python VENV:
source /opt/automation-gateway/.venv/bin/activate && which python3
Sourcing the VENV first will ensure the ansible and python binaries are the correct ones being used by Automation Gateway.
Step 1: Install the Nodegrid collection
Perform the following actions to install the Nodegrid Collection:
- Download the repository using the following command:
git clone https://github.com/ZPESystems/Ansible.git
- Enter into the ansible directory.
cd Ansible
- Build the library using the
build.py
script.
python3 build.py
- Install the collection with ansible-galaxy.
ansible-galaxy collection install -r build/collections/requirements.yml --force
- In the
/etc/ansible/ansible.cfg file
, define the keyinterpreter_python
with the location of the Python interpreter. This is the minimalansible.cfg
recommended file content:
[defaults]
interpreter_python = /usr/bin/python3
gathering = explicit
host_key_checking = False
[ssh_connection]
ssh_args = -o ControlMaster=no -o ControlPersist=3600s -o PreferredAuthentications=publickey
Step 2: Install ZPE Cloud collection
Once the Nodegrid Collection is installed in the Automation platform, you must install the ZPE Cloud collection to access the ZPE Cloud features. The installation workflow involves the following steps:
- Download and install the ZPE Cloud collection.
- Set up a dynamic inventory.
- Set up the connection plugin.
Step 3: Install the connection plugin
Before installing, ensure the following prerequisites are met:
- Nodegrid version 5.6.5 or higher is recommended.
- An account with ZPE Cloud based on which the inventory is created.
Follow these steps to install the ZPE Cloud collection:
- On the Ansible controller, install the ZPE Cloud collection:
ansible-galaxy install zpe.zpecloud
2. Set up the zpecloud
dynamic inventory plugin by creating a file called zpecloud.yml
in the ansible inventory folder. Provide the following details:
plugin: zpe.zpecloud.zpecloud_nodegrid_inventory
url: https://zpecloud.com
username: youruser@email.com
password: yourpassword
organization: yourcompanyname
- If the URL field is left unassigned, then
zpecloud.com
is set as the default value. - The
organization
field is required only if the user has more than one organization associated with the account. This field is case-sensitive.
3. Test the inventory connection using this command to display the list of available devices:
ansible-inventory --graph
.
4. After setting up the Inventory plugin, you will need to set up the connection plugin by providing the same details as those provided during the inventory setup. This plugin is used to access the ZPE Cloud API. In the ansible inventory folder, create a group_vars
folder and create a file called zpecloud_device_enrolled.yml
and provide the following details:
"ansible_connection": zpe.zpecloud.zpecloud
"ansible_zpecloud_username": "youruser@email.com"
"ansible_zpecloud_password": "password"
"ansible_zpecloud_organization": "yourcompanyname" #
"ansible_python_interpreter": "/usr/bin/python3"
You now have all the required components installed and can start creating and running a playbook.
Step 4: Create and run a playbook
In this step, you will create a sample playbook executed against the online Nodegrid devices in the inventory and display the gathered default facts from the specific Nodegrid device.
- In your Ansible playbook directory, create the following sample playbook file called
zpecloud_get_facts.yml
using the following content.
name: Get Ansible Facts
hosts: zpecloud_device_online
gather_facts: True
tasks:
- name: Display Systems Facts
debug:
var: ansible_facts
2. Once the playbook is created, use the following command to run it.
ansible-playbook zpecloud_get_facts.yml
Step 5: Make ZPE Cloud work with Automation Gateway
In Automation Gateway, navigate to Configuration → Automation Gateway → Ansible.
Under the section labeled Inventory File, set your path to the full path of your zpecloud.yml
file:
/opt/automation-gateway/ansible/inventory/zpecloud.yml
Then restart Automation Gateway to initialize the new external (dynamic) inventory.
systemctl restart automation-gateway
Figure: ZPE Cloud Inventory File