Nathan Lin

Accessing iLO Redfish APIs and HPE OneView APIs on Ansible AWX

February 9, 2021

There has been a growing demand in infrastructure management automation and an adaption toward infrastructure-as-code (IAC) with Ansible and AWX. Backed by Red Hat, Ansible has become one of the most popular IAC toolings for its simple and easy to understand coding style, masterless and agentless design, and the ability to create custom playbooks and roles for providing extra support to process automation. AWX, on the other hand, is the open-sourced version of Ansible Tower, which along with a set of tools, provides a web-based graphical user interface hub for consuming Ansible playbooks.

Both the HPE Python iLO REST Library and the HPE OneView SDK for Ansible do not come bundled with AWX. The AWX project does provide instructions on managing custom Python dependencies on AWX. This blog post is to share the process that we took to set up a custom Python environment for the Python iLO REST Library and the HPE OneView SDK in order to access the iLO Redfish APIs and the HPE OneView APIs from an AWX job.

Ansible and AWX setup on localhost

Ansible and AWX setup instructions can be found here on GitHub. If running behind proxies, make sure the proxy parameters, such as httpproxy, httpsproxy, and noproxy_ are configured accordingly in the installation inventory file. Once installation completes, the Ansible command becomes available on the localhost, and AWX runs as a containerized application, as shown here:

bash-4.4# ansible --help
usage: ansible [-h] [--version] [-v] [-b] [--become-method BECOME_METHOD]
               [--become-user BECOME_USER] [-K] [-i INVENTORY] [--list-hosts]
               [-l SUBSET] [-P POLL_INTERVAL] [-B SECONDS] [-o] [-t TREE] [-k]
               [--private-key PRIVATE_KEY_FILE] [-u REMOTE_USER]
               [-c CONNECTION] [-T TIMEOUT]
               [--ssh-common-args SSH_COMMON_ARGS]
               [--sftp-extra-args SFTP_EXTRA_ARGS]
               [--scp-extra-args SCP_EXTRA_ARGS]
               [--ssh-extra-args SSH_EXTRA_ARGS] [-C] [--syntax-check] [-D]
               [-e EXTRA_VARS] [--vault-id VAULT_IDS]
               [--ask-vault-pass | --vault-password-file VAULT_PASSWORD_FILES]
               [-f FORKS] [-M MODULE_PATH] [--playbook-dir BASEDIR]
               [-a MODULE_ARGS] [-m MODULE_NAME]
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                COMMAND                  CREATED      STATUS      PORTS                  NAMES
79248db66699   ansible/awx:17.0.1   "/usr/bin/tini -- /u…"   5 days ago   Up 5 days   8052/tcp               awx_task
11e9c78d53cf   ansible/awx:17.0.1   "/usr/bin/tini -- /b…"   5 days ago   Up 5 days>8052/tcp   awx_web
46c529f34016   postgres:12          "docker-entrypoint.s…"   5 days ago   Up 5 days   5432/tcp               awx_postgres
75c8e09ad2de   redis                "docker-entrypoint.s…"   5 days ago   Up 5 days   6379/tcp               awx_redis

Installing the HPE libraries on AWX

The installation of the HPE Python iLO REST library and the HPE OneView Ansible library can be achieved by the following three steps:

  1. Log in to the awxtask_ container. Create a custom Python virtual environment and install the HPE Python iLO REST library and the HPE OneView Ansible library using the Python package manager.

  2. Log in to the awxweb containers. Create a new virtual environment with the same name as the one newly created in the awxtask container, and then install these two HPE Python libraries again using the Python package manager.

  3. Lastly, add the new Python environment to the customvirtualenvs_ in AWX through its REST APIs.

Keep in mind to create the virtual environments first in awxweb and awxtask before adding it to the AWX custom virtual environment. The following sections talk more about each of the steps.

Create new custom virtual environments on awxtask and awxweb

First, access the container BASH shell with the command Docker exec -it . For example, accessing the awx task shell :

[root@localhost ~]# docker exec -it awx_task /bin/bash

Within the container, create a new Python virtual environment. For this example, the virtual environment is created at /opt/hpeAutomation/venv:

bash-4.4# mkdir -p /opt/hpeAutomation/
bash-4.4# chmod 0755 /opt/hpeAutomation/
bash-4.4# python3 -m venv /opt/hpeAutomation/venv

Install the HPE libraries on awxtask and awxweb

On each of the AWX containers, proceed as follows:

  1. YUM install the pre-requisites gcc:
bash-4.4# yum install gcc -y
  1. Install the psutil Python module and the HPE libraries:
bash-4.4# /opt/hpeAutomation/venv/bin/pip3 install psutil
bash-4.4# /opt/hpeAutomation/venv/bin/pip3 install ansible hpOneView hpICsp python-ilorest-library
bash-4.4# git clone
bash-4.4# cd oneview-ansible
bash-4.4# cp library/*.py  /opt/hpeAutomation/venv/lib/python3.6/site-packages/ansible/modules/remote_management/oneview/
bash-4.4# cp library/module_utils/  /opt/hpeAutomation/venv/lib/python3.6/site-packages/ansible/module_utils

Configure the customvirtualenvs_ in AWX

Once finished installing the Python modules to awxtask and awxweb , the last step is to add the newly created virtual environment to customvirtualenvs_ in AWX. This can be done with a HTTP PATCH to the AWX:

[root@localhost ~]# curl -X PATCH http://AWX_admin_username:AWX_adminpassword@AWX_ip_address/api/v2/settings/system/ \
-d '{"CUSTOM_VENV_PATHS": ["/var/lib/awx/venv/ansible", "/opt/hpeAutomation/"]}' \
-H 'Content-Type:application/json'

You can verify the customvirtualenvs in AWX with a HTTP GET request to /api/v2/config/_ , as shown below:

[root@localhost ~]# curl -u AWX_admin_username:AWX_admin_password http://AWX_IP_address/api/v2/config/
  "time_zone": "UTC",
  "license_info": {
    "license_type": "open",
    "valid_key": true,
    "subscription_name": "OPEN",
    "product_name": "AWX"
  "custom_virtualenvs": [

Once completed, the custom virtual environment becomes available as an Ansible Environment in the AWX Projects and the Python libraries become accessible by the Job Templates in the project. project template

There you have it. The AWX is now ready to run jobs for HPE OneView and iLO.


François Donzé

Benefits of the Platform Level Data Model for Firmware Update Standard

Jun 7, 2022
François Donzé

Build your own iLO Redfish simulator

Jun 11, 2021
HPE Global Sales Engineering (GSE) team

Automate boot from SAN target configurations using Redfish

Jun 1, 2023
François Donzé

CHIF driver not found

Jun 22, 2021
Gokul Sreeramaiah

Configuring threads for Optimal performance in HPE PowerShell Cmdlets

Dec 3, 2018
HPE DEV staff

COVID-19 limits accessibility – Free offer for HPE iLO Advanced opens it up

Apr 23, 2020
Matthew Kocurek - iLOREST Developer

Creating a Python version that enforces FIPS

Feb 15, 2018
Naveen Gupta

Discover the power of data center monitoring using Redfish telemetry and cloud-native tooling: Part 2 - Streaming

Dec 1, 2023

HPE Developer Newsletter

Stay in the loop.

Sign up for the HPE Developer Newsletter or visit the Newsletter Archive to see past content.

By clicking on “Subscribe Now”, I agree to HPE sending me personalized email communication about HPE and select HPE-Partner products, services, offers and events. I understand that my email address will be used in accordance with HPE Privacy Statement. You may unsubscribe from receiving HPE and HPE-Partner news and offers at any time by clicking on the Unsubscribe button at the bottom of the newsletter.

For more information on how HPE manages, uses, and protects your personal data please refer to HPE Privacy Statement.