Sep
24
2020 Posted by James Gill

Ansible on z/OS – 1 – Enterprise Python

Introduction

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.

 

What Is…?

In case you haven’t encountered these tools before:

 

Ansible

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

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:

www.python.org

 

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:

https://www.rocketsoftware.com/product-categories/mainframe/python-for-zos

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:

https://www.ibm.com/products/open-enterprise-python-zos/pricing

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:

usr/lpp/IBM/cyp/v3r8/

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

mkdir /usr/lpp/IBM/cyp

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:

export PATH=$PATH:/usr/lpp/IBM/cyp/v3r8/pyz/bin
export LIBPATH=$LIBPATH:/usr/lpp/IBM/cyp/v3r8/pyz/lib

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.

/u/myid/.profile

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:

python3 --version

Your output should be something like this:

MYID:/u/myid: >python3 --version
Python 3.8.3

 

What Can We Do?

There’s always the traditional “Hello World” sample – albeit with our own twist:

# hello.py - example
print("Hello Geeks")

MYID:/u/myid: >python3 hello.py
Hello Geeks

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
Package Version
------------ -------
cffi 1.14.0
cryptography 2.8
ebcdic 1.1.1
numpy 1.18.2
pip 20.1.1
pycparser 2.20
setuptools 46.4.0
six 1.15.0
zos-util 1.0.0

 

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:

1. certifi
2. chardet
3. idna
4. urllib

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.

 

Next Time

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

« Previous | Next »
Have a Question?

Get in touch with our expert team and see how we can help with your IT project, call us on +44(0) 870 2411 550 or use our contact form…