ZPE Cloud dynamic inventory

To create and manage device inventory via plugin, several steps are required. This guide covers the Nodegrid and ZPE Cloud plugin.

Prerequisites

Verify you are using the correct Ansible and Python binaries. Depending on your setup in Itential Automation Gateway (IAG), it will change how you perform a few of the steps below.

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

If you are using a Python VENV (virtual environment), source the VENV first:

$source /opt/automation-gateway/.venv/bin/activate

Then 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 IAG.

1

Install the Nodegrid collection

  1. Download the repository:

    $git clone https://github.com/ZPESystems/Ansible.git
  2. Enter the Ansible directory:

    $cd Ansible
  3. Build the library using the build.py script:

    $python3 build.py
  4. Install the collection with ansible-galaxy:

    $ansible-galaxy collection install -r build/collections/requirements.yml --force
  5. In the /etc/ansible/ansible.cfg file, define the key interpreter_python with the location of the Python interpreter. This is the minimal recommended ansible.cfg content:

    1[defaults]
    2
    3interpreter_python = /usr/bin/python3
    4
    5gathering = explicit
    6
    7host_key_checking = False
    8
    9[ssh_connection]
    10
    11ssh_args = -o ControlMaster=no -o ControlPersist=3600s -o PreferredAuthentications=publickey
2

Install ZPE Cloud collection

Once the Nodegrid collection is installed in IAG, install the ZPE Cloud collection to access ZPE Cloud features. The installation process involves the following steps:

  1. Download and install the ZPE Cloud collection.
  2. Set up a dynamic inventory.
  3. Set up the connection plugin.
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.
  1. 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 with the following content:

    1plugin: zpe.zpecloud.zpecloud_nodegrid_inventory
    2url: https://zpecloud.com
    3username: youruser@email.com
    4password: yourpassword
    5organization: yourcompanyname
    • If the URL field is left unassigned, zpecloud.com is set as the default value.
    • The organization field is required only if you have more than one organization associated with the account. This field is case-sensitive.
  3. Test the inventory connection to display the list of available devices:

    $ansible-inventory --graph
  4. Set up the connection plugin by providing the same details used 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 a file called zpecloud_device_enrolled.yml with the following content:

    1"ansible_connection": zpe.zpecloud.zpecloud
    2"ansible_zpecloud_username": "youruser@email.com"
    3"ansible_zpecloud_password": "password"
    4"ansible_zpecloud_organization": "yourcompanyname"
    5"ansible_python_interpreter": "/usr/bin/python3"

You now have all the required components installed and can start creating and running a playbook.

4

Create and run a playbook

Create a sample playbook executed against the online Nodegrid devices in the inventory to display the gathered default facts from the specific Nodegrid device.

  1. In your Ansible playbook directory, create a sample playbook file called zpecloud_get_facts.yml with the following content:

    1name: Get Ansible Facts
    2hosts: zpecloud_device_online
    3gather_facts: True
    4tasks:
    5 - name: Display Systems Facts
    6debug:
    7 var: ansible_facts
  2. Run the playbook:

    $ansible-playbook zpecloud_get_facts.yml
5

Make ZPE Cloud work with IAG

In IAG, navigate to Configuration > Automation Gateway > Ansible.

Under the Inventory File section, set your path to the full path of your zpecloud.yml file:

$/opt/automation-gateway/ansible/inventory/zpecloud.yml

Restart IAG to initialize the new external (dynamic) inventory:

$systemctl restart automation-gateway
ZPE Cloud inventory file configuration