Ansible on z/OS – 1 – Enterprise Python
We had been using Ansible to automate the installation of zPDT on Red Hat VMs for a couple of years before the version for z/OS was released. The power of Ansible is largely down to it’s enthusiastic open developer community and the huge number of plugins (think Jenkins) which provide support for many, many things.
This blog will have to be a series, or it will turn into a book. It will attempt to cover the installation and use of Ansible on z/OS, and a look into the available features (core, plugins, etc) as well as some use examples and we’ll have a crack at writing a plugin to round it all off.
This first part will focus on one of the pre-reqs – Python.
In case you haven’t encountered these tools before:
Ansible is an automation tool used to support provisioning of software. It can do a lot more than that, but the automation is what we’re interested in on z/OS. As well as core functionality (submit a job, issue a TSO command) it has plugins available to support interaction with zOSMF, CICS and IMS, with more being written every day.
The (current) pre-reqs for Ansible on z/OS are:
- z/OS 2.3 and up
- IBM Open Enterprise Python for z/OS – see below
- IBM Z Open Automation (ZOA) Utilities
- Open SSH
- IBM z/OS shell (/bin/sh) in USS
Python is an interpreted general purpose programming language. It has an active developer community and whilst initially popular in the scientific community, has spread far and wide. You can read more at:
Python Distros on z/OS
As well as the IBM Open Enterprise Python distribution, Rocket Software also have a long standing offering, which can be found in their website:
We will concentrate on the IBM offering, as it is listed as a pre-req for Ansible.
Installing IBM Open Enterprise Python for z/OS PAX Edition
The IBM Python is offered in two forms – a free / trial PAX download and a supported SMP/E delivery. For the sake of our R&D budget, we’re using the PAX version, downloaded directly from IBM here:
The PAX download is available on the page, even though the URL ends in the word “pricing”.
Once uploaded to a large enough USS filesystem (the download is c.237MB), it can be unpacked from the IBM shell (TSO OMVS) using:
zcat HAMB380.runnable.pax.Z | pax -r
This delivers the following directory structure, which requires an additional 413MB:
In our case, this was in a filesystem mounted off a user directory (/u/myid/python), so we juggled things around a bit:
mv usr/lpp/IBM/cyp/v3r8 ./
rm -rf usr
And then un-mount the filesystem and remount it from TSO:
Configuring Your Shell Session to Use Python
The IBM shell (USS command prompt) uses environment variables to tell it where to load programs and libraries from. You can update these for the lifetime of the session using:
If you want to make the changes more permanent, apply them to the shell profile which is in you user HOME directory – called .profile (don’t miss the leading dot), e.g.
Or if this is to be rolled out to everyone, get it applied to the /etc/profile.
To verify the configuration changes, ask python which version it is:
Your output should be something like this:
MYID:/u/myid: >python3 --version
What Can We Do?
There’s always the traditional “Hello World” sample – albeit with our own twist:
# hello.py - example
MYID:/u/myid: >python3 hello.py
The python package manager and install tool pip is also included, which allows us to install supporting packages to expand our range a little. Here’s a quick run through some bits that might be useful:
pip – What’s Already Installed?
MYID:/u/myid: >pip3 list
pip – How Do We Install Another Package?
Our z/OS service isn’t connected to the internet, so we did it like this:
1. On a laptop with Python and pip installed:
a. mkdir requests
b. cd requests
c. pip download requests
i. This pulled the “requests” package and four dependencies:
d. Binary FTP all five to a USS directory (/u/myid/pipdl)
2. On z/OS, in USS in the directory we uploaded to, install all of the packages using:
pip3 install requests --find-links ./
Note lots of error messages as pip tries to access the internet version, but then success at the end.
Repeating the list of installed packages:
Some Example Python Code
In a previous blog about the DB2 for z/OS REST API, we shared some Python example code for driving one of our example services. The service does a -DISPLAY THREAD(*) in DB2 and returns the output. Here’s the Python code (driveDisThread.py) – lightly modified for the user that I’m using:
Running the code:
Other than a small environmental change (the userid/pwd), this code has run entirely unmodified from the previous use, when it was executed on a Windows machine.
In the next blog in this series, we’ll look at getting the IBM Z Open Automation (ZOA) Utilities installed and running. As well as being a pre-req for the Ansible installation that we’re working towards, they are also extremely useful for other open solutions – e.g. a z/OS Jenkins node.
View all blogs in James Gill’s Ansible series.