Informing the IBM Community

Using Ansible with IBM i to install PTFs

0
(0)

In my previous article I introduced you to using the ibm.power_ibmi Ansible collection from IBM. I showed how to connect to your IBM i LPAR and vary on and off a device. Whilst that is mildly useful I wanted to write about something slightly more complex and, arguably, more useful. The ibmi_fix_imgclg module allows you to install one or more PTFs via an *IMGCLG. The beauty of this module is that you do not need to have an existing optical device or image catalogue, the Ansible module creates temporary *DEVD and *IMGCLG objects for the installation and then cleans up when complete.

There are several prerequisite tasks required before you can start to use the instructions in this article. If you have already been through the previous article you should be fine to move on. If not, I would advise you go through the previous article to make sure you have everything set up correctly. Also, Stu Cunliffe from IBM has a great introduction to Ansible for IBM Power systems users on the IBM Power VUG webinar sessions.

Latest ibm.power_ibmi collection

Since my previous article in July 2020 the Ansible for i team have updated the ibm.power_ibmi collection to v1.0.1 so if you previously installed v1.0.0 you will need to force the install of the new version of the collection using:

Warning: In my previous article we created files in the ~/.ansible/collections/ansible_collections/ibm/power_ibmi/ folder. This is not the way we would normally create playbooks etc. Best practise is to create a folder per Ansible project, so you would never create your own files under the ~/.ansible/collections folder.

The command above with –force will overwrite the contents of ~/.ansible/collections/ansible_collections/ibm/power_ibmi/.

Project files and folders

With the collection downloaded we need to create a file structure to use for our project so that we keep our files separate from the collections.

I tested the ibmi_fix_imgclg module by installing PTF SI72134 for product 5733-SC1. Go to IBM fix central and download that PTF, or any other you wish, on to your PC. The Ansible playbook will copy the file to your IBM i LPAR in preparation for installation.

Add the following to the ansible.cfg file:

ubuntu$ touch inventory.yml

Add the following to the inventory.yml file. Please note that indentation is very important:

If you have not created an SSH keypair already create this on your Linux system and copy the .pub file to the /home/<YOUR_USER_ID> IFS folder on your IBM i LPAR. You will need to create this folder on your LPAR IFS if it does not already exist.

The ansible_id_rsa and ansible_id_rsa.pub files will be created and stored in the .ssh directory in your home directory e.g. /home/robinsg/.ssh

Copy the id_rsa.pub file to the LPAR

Now ssh on to the IBM i LPAR. Make sure the *SSHD server is running before you try.

You should get an SSH session on to the IFS of your LPAR without having to enter a password.

Now, let’s create our playbook which will run the tasks to:

  • Retrieve info for the PTF we wish to install
  • If the PTF is already found, display a message and end the play
  • If the PTF is NOT installed or loaded, copy the Fix Central PTF file to the /tmp folder on the IFS
  • Create an image catalogue and virtual optical device and use the file in /tmp to install and apply the PTF

Now copy and paste the following in the install_ptfs_via_imgclg.yml file:

As before, the indentations are important as this is a YAML file.

Notice that the top of the playbook has a number of lines below the vars keyword. These can be set to whatever values you wish if you decide to use a different PTF ID and/or product. Also, you will need to change src_dir and bin_file to the location and file name of your Fix Central downloaded PTF file.

Run the playbook

Before we run the playbook let’s do a syntax check:

As long as this doesn’t return any errors your playbook should be fine.

Let’s run the playbook to install the PTF:

The display PTF task returns an error as the PTF is not loaded. The playbook traps the error, ignores it and continues to upload the Fix Central PTF file to the IFS and then installs the PTF using a temporary image catalogue.

Here’s what I detected when the PTF was installing:

These show that Ansible created an optical device called ANSIBOPT1 and an image catalogue called ANSIBCLG1 for with the PTF file. A temporary directory was also created in /tmp. These objects were deleted by Ansible when the playbook completed.

The uploaded file Fix Central PTF file is not deleted.

Just to prove the PTF was installed:

Let’s run the playbook again to see what happens if the PTF is already installed:

The playbook detects that the PTF is already loaded or installed on the system and ends the playbook without uploading or attempting to reinstall. You could change this in the playbook to any actions you desire. I included the check just to show that we can use some conditional functionality in our playbook.

What else can we do?

As well as the ibmi_fix_imgclg module there is also an ibmi_fix module. This allows PTFs to be queried, deleted and installed. The install option allows multiple PTFs to be installed but expects the PTF(s) to located in Save Files in a library e.g. QGPL.

References:

Ansible websitehttps://www.Ansible.com/
Ansible installationhttps://docs.Ansible.com/Ansible/latest/installation_guide/intro_installation.html
Generate and copy an ssh keypairhttps://www.ssh.com/ssh/copy-id
Ansible for i module documentationhttps://ibm.github.io/ansible-for-i/modules.html
IBM i opensource repositoryhttps://bitbucket.org/ibmi/opensource/src/master/
IBM Power VUG Webinar Serieshttps://www.ibm.com/support/pages/power-vug-technical-webinar-series#Past%20Session%20Replays
Ansible Automation on Power IBM Power VUG by Stuart Cunliffe, IBM Lab Serviceshttps://www.ibm.com/support/pages/power-vug-technical-webinar-series#96
Github issue for enable_offline_ibm when trying to install pythonhttps://github.com/IBM/ansible-for-i/issues/35

Acknowledgements:

Stuart Cunliffe, IBM Lab Services for allowing me to reference his Ansible for Power webinar

Adam Robinson, Maple Computing for assisting me with testing the above

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.


Comments

One response to “Using Ansible with IBM i to install PTFs”

  1. Can we install CUME PTF via this module? If yes then how ?

Leave a Reply

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