ZPE Cloud Automation with Ansible

Prev Next

The ZPE Cloud and Nodegrid Ansible collections enable automated configuration, system preference management, and OS upgrades for Nodegrid devices. Define tasks in Ansible playbooks to execute sequential profile configurations reliably across your network.

Understanding the workflow

To understand the workflow consider the following diagram.

Step 1:

  • The customer creates a playbook that contains a sequence of tasks written in Ansible scripts.

  • The Nodegrid module translates Ansible tasks into CLI configuration commands compatible with the target devices.

  • The ZPE Cloud module facilitates cloud-based operations related to the network infrastructure.

  • The ZPE Cloud API plugin establishes a transport method for communicating with Nodegrid devices securely.

Step 2:

  • The connection plugin in Ansible utilizes the ZPE Cloud API for communication with the Nodegrid devices.

  • User authentication is required for accessing the ZPE Cloud API, ensuring secure communication via HTTPS protocol.

Step 3:

  • Each task received from Ansible is converted into corresponding profiles within the ZPE Cloud platform.

  • ZPE Cloud applies the generated script profiles to the target devices and retrieves the execution output upon completion.

  • Once the tasks are executed, the corresponding profiles are deleted from the ZPE Cloud platform for security and maintenance purposes.

  • Audit logs are generated for each action performed, ensuring accountability and traceability of operations.

Step 4:

  • The profile, converted into a Python script, executes within the Nodegrid device environment.

  • The Python script within Nodegrid interacts with CLI configurations performs software upgrades, applies backups, and other specified tasks.

Step-by-step Guide 

To use the Nodegrid and ZPE Cloud Collection in your Automation platform, you must: 

  1. Install the Nodegrid Collection 

  2. Install ZPE Cloud Collection 

  3. Install the connection Plugin

  4. Create and run a playbook 

How to install the ZPE Cloud Collection?

Installation

  • The Nodegrid Version 5.6.5 or higher is recommended.

  • An account with ZPE Cloud based on which the inventory is created.

A step-by-step guide to installing the ZPE Cloud collection:

  1. Download and Install the collection:

    1. On the Ansible controller install the ZPE Cloud collection:

      $ ansible-galaxy collection install zpe.zpecloud

Configuration

  1. Set up a dynamic Inventory:

    1. Set up the zpecloud dynamic inventory plugin by creating a file called zpecloud.yml in your 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.

    2. Test your inventory connection using the following command to display the list of available devices.

      ansible-inventory --graph

How to Create and Run a Playbook

In this section, 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.

  1. Create a playbook

    1. 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. Run a Playbook
    Once you create a playbook, you can use the following command to run it.

    ansible-playbook zpecloud_get_facts.yml

    Let us now look at other sample tasks that you can include in a playbook. 

Other Sample Playbook Tasks

Playbooks can contain multiple tasks to configure different functionalities from Nodegrid. The following snippets describe each task inside the playbook.

Apply software upgrade to Nodegrid device via ZPE Cloud

Users can add software upgrade tasks to Ansible playbooks by adding the task zpe.zpecloud.software_upgrade. This module is provided inside the ZPE Cloud's Ansible collection.

 This task contains the following two parameters:

  •  version: Desired version of Nodegrid OS in the following format: <major>.<minor>.<patch> (for example, 5.10.10)

  •  allow_downgrade: If true, permits Ansible to downgrade a device. This is a security flag to prevent devices from being downgraded by mistake, or factory resetting the box.

 The following snippet presents a playbook that upgrades a device to Nodegrid version 6.0.3 via ZPE Cloud. If the device has a version greater than that, the execution will fail since the allow_downgrade field is set to false.

name: Copy a file from nodegrid
  hosts: "zpecloud_device_enrolled"
  gather_facts: no
  collections:
    - zpe.zpecloud
  tasks:
    - name: Apply software upgrade profile to device
      zpe.zpecloud.software_upgrade:
        version: "6.0.3"
        allow_downgrade: false

Update System Preferences

The following snippet updates the system settings such as hostname,  ideal timeout, banner, and so on.

 name: Set system preferences
      block:
        - name: Set /settings/preferences
          zpe.nodegrid.system:
            preferences:
              show_hostname_on_webui_header: "yes"
              idle_timeout: "4321"
              enable_banner: "yes"
              banner: "{{ device_model }}"
              coordinates: "37.4769561,-121.9435728"

Enable Remote Access

The following snippet as the name suggests enables remote access to the Nodegrid device through the ZPE Cloud.

 name: Enable ZPE Cloud remote access
          zpe.nodegrid.import_settings:
            cmds:
              - "/settings/zpe_cloud enable_remote_access=yes"

Changing Hostname

The following snippet as the name suggests changes the hostname of the Nodegrid device:

name: Configure hostname
          zpe.nodegrid.network:
            settings:
              hostname: "{{ device_model }}"

These are some examples of the tasks you can execute in a playbook. 

How to Verify the Tasks in ZPE Cloud?

Once you run a playbook and execute tasks, you can log in to the ZPE Cloud to know the details of jobs performed:

  1. Log in to ZPE Cloud.

  2. Go to PROFILES :: OPERATIONS. You can view the details of the jobs that are executed using the Ansible playbook.


    On this page, you can view details such as the model of the device, the serial number, the hostname, the type of operation, the status of the operation, the start time, and the end time of the operation. The detailed output of each script is displayed in the Ansible console while executing the playbook. This page will only show which scripts were executed on the device and whether they were executed successfully.