The phrase “I can’t even spell….” is a British phrase which means “I know so little about this that I cannot even pronounce or write the word.”
I wanted to see if I could use Ansible to extract some information from z/OS. There is a lot of documentation available, but it felt like the documentation started at chapter 2 of the instruction book, and missing the first set of instructions.
Below are the instructions to get the most basic ping request working.
On z/OS
Ansible is a python package which you need to install.
pip install ansible-core
This may install several packages
It is better to do this in an SSH terminal session rather than from ISPF -> OMVS. For example it may display a progress bar.
On Linux
Setup
sudo apt install ansible
I made a directory to store my Ansible files in
mkdir ansible cd ansible
There is some good documentation here.
Edit the inventory.ini
[myhosts]
10.1.1.2
[myhosts:vars]
ansible_python_interpreter=/usr/lpp/IBM/cyp/v3r12/pyz/bin/python
Where
- [myhosts]… is the IP address of the remote system.
- [myhosts:vars] ansible_python_interpreter=… is needed for Ansible to work. It it the location of Python on z/OS.
Check the connection
Ansible uses an SSH session to get to the back end.
ssh colin@10.1.1.2
I have set this up for password less logon. Check it works before you try to use Ansible.
Try the ping
ansible myhosts -u colin -m ping -i inventory.ini
Where
- -i inventory.ini specifies the configuration file
- myhosts which sections in the configuration file
- -u colin logon with this userid
- -m ping and issue this command
When this worked I got
10.1.1.2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
The command took about 10 seconds to run.
You may not need to specify the -u information.
What can go wrong?
I experienced
Invalid userid
ansible myhosts -u colinaa -m ping -i inventory.ini
10.1.1.2 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: colinaa@10.1.1.2: Permission denied (publickey,password).",
"unreachable": true
}
This means you got to the system, but you specified an invalid user, or the userid was unable to connect over SSH.
Python configuration missing
ansible myhosts -u colin -m ping -i inventory.ini
This originally gave me
[WARNING]: No python interpreters found for host 10.1.1.2 (tried ['python3.12', 'python3.11',
'python3.10', 'python3.9', 'python3.8', 'python3.7', 'python3.6', '/usr/bin/python3',
'/usr/libexec/platform-python', 'python2.7', '/usr/bin/python', 'python'])
10.1.1.2 | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"module_stderr": "Shared connection to 10.1.1.2 closed.\r\n",
"module_stdout": "/usr/bin/python: FSUM7351 not found\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 127
}
Edit the inventoy.ini and add the ansible_python_interpreter information.
[myhosts]
10.1.1.2
[myhosts:vars]
ansible_python_interpreter=/usr/lpp/IBM/cyp/v3r12/pyz/bin/python