IBM / ansible-for-i

the tool is to provide several customized modules for Ansible to manage IBM i systems.
GNU General Public License v3.0
56 stars 54 forks source link

Ansible yum core module not found with IBM i #61

Open robinsg opened 3 years ago

robinsg commented 3 years ago

I'm not sure if this an Ansible for i or an IBM Open Source issue but I thought I'd start here.

Issue:

I'm running a number of playbooks using core and power_ibmi modules which work fine, except yum or package.

I have a role which uses yum to update all packages and another to install some additional packages. When these run I get an error message saying that yum is not found and that ansible.pkg_mgr is unknown.

If I log in to the LPAR using ssh and run yum install vim -y this works fine.

The yum executable is located in /QOpenSys/pkgs/bin and this is in PATH, as you can see below.

The LPARs have V7R3 installed with the latest PTFs and the latest repo updates.

How do I set yum as the ansible.pkg_mgr?

Attempts to workaround I noticed that Ansible was executing /bin/sh on the LPAR so I have overridden this with ansible_shell_executable=/QOpenSys/pkgs/bin/bash.

I also noticed that /QOpenSys/pkgs/bin wasn't in the PATH when I ran an ad-hoc command or playbook. I added a PATH environment variable to the playbook, see the path shown below.

I've also tried using the package module specifying use: yum

Neither of these three made any difference.

Recreate the issue

$ ansible mylpar -m yum -a "name=vim state=present" -vvvv

Output

ansible 2.9.14
 config file = /home/grobinso/ansible/dev/IBMiV7R3Upgrades/playbooks/ansible.cfg
 configured module search path = [u'/home/grobinso/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
 ansible python module location = /usr/lib/python2.7/site-packages/ansible
 executable location = /usr/bin/ansible
 python version = 2.7.5 (default, Mar 20 2020, 21:13:12) [GCC 4.8.5 20150623 (Red Hat 4.8.5–39)]
Using /home/grobinso/ansible/dev/IBMiV7R3Upgrades/playbooks/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /home/grobinso/ansible/dev/IBMiV7R3Upgrades/playbooks/inventory.yaml as it did not pass its verify_file() method
script declined parsing /home/grobinso/ansible/dev/IBMiV7R3Upgrades/playbooks/inventory.yaml as it did not pass its verify_file() method
Parsed /home/grobinso/ansible/dev/IBMiV7R3Upgrades/playbooks/inventory.yaml inventory source with yaml plugin
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/minimal.pyc
META: ran handlers
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/setup.py
Pipelining is enabled.
<mylpar.local> ESTABLISH SSH CONNECTION FOR USER: grobinso
<mylpar.local> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="/home/grobinso/.ssh/gr_ansible_id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="grobinso"' -o ConnectTimeout=10 -o ControlPath=/home/grobinso/.ansible/cp/1c77abd70c mylpar.local '/QOpenSys/pkgs/bin/bash -c '"'"'/QOpenSys/pkgs/bin/python2 && sleep 0'"'"''
<mylpar.local> (0, '\n{"invocation": {"module_args": {"filter": "ansible_pkg_mgr", "gather_subset": ["!all"], "fact_path": "/etc/ansible/facts.d", "gather_timeout": 10}}, "ansible_facts": {"ansible_pkg_mgr": "unknown"}}\n', 'OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017\r\ndebug1: Reading configuration data /home/grobinso/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 1558\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ntput: unknown terminal "dumb"\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
mylpar | FAILED! => {
 "ansible_facts": {
 "pkg_mgr": "unknown"
 },
 "changed": false,
 "msg": "Could not find a yum module backend for unknown."

Ansible Facts

mylpar | SUCCESS => { [36/510]
 "ansible_facts": {
 "ansible_apparmor": {
 "status": "disabled"
 },
 "ansible_architecture": "007800012345",
 "ansible_date_time": {
 "date": "2020–11–20",
 "day": "20",
 "epoch": "1605865065",
 "hour": "09",
 "iso8601": "2020–11–20T09:37:45Z",
 "iso8601_basic": "20201120T093745282658",
 "iso8601_basic_short": "20201120T093745",
 "iso8601_micro": "2020–11–20T09:37:45.282658Z",
 "minute": "37",
 "month": "11",
 "second": "45",
 "time": "09:37:45",
 "tz": "GMT",
 "tz_offset": "GMT",
 "weekday": "Friday",
 "weekday_number": "5",
 "weeknumber": "46",
 "year": "2020"
 },
 "ansible_distribution": "OS400",
 "ansible_distribution_release": "3",
 "ansible_distribution_version": "7",
 "ansible_dns": {},
 "ansible_domain": "local",
 "ansible_effective_group_id": 0,
 "ansible_effective_user_id": 485,
 "ansible_env": {
 "HOME": "/home/grobinso",
 "LOGIN": "grobinso",
 "LOGNAME": "grobinso",
 "MAIL": "/var/spool/mail/grobinso",
 "PATH": "/QOpenSys/usr/bin:/usr/ccs/bin:/QOpenSys/usr/bin/X11:/usr/sbin:.:/usr/bin",
 "PWD": "/home/grobinso",
 "SHELL": "/QOpenSys/pkgs/bin/bash",
 "SHLVL": "2",
 "SSH_CLIENT": "1.2.3.4 53984 22",
 "SSH_CONNECTION": "1.2.3.4 53984 1.2.3.5 22",
 "TERM": "xterm",
 "TZ": "<GMT>0<BST>,M3.5.0,M10.5.0",
 "USER": "grobinso",
 "_": "/QOpenSys/pkgs/bin/python2"
 },
 "ansible_fips": false,
 "ansible_fqdn": "mylpar.local",
 "ansible_hostname": "MYLPAR",
 "ansible_hostnqn": "",
 "ansible_is_chroot": true,
 "ansible_iscsi_iqn": "",
 "ansible_kernel": "3",
 "ansible_kernel_version": "7",
 "ansible_local": {},
 "ansible_lsb": {},
 "ansible_machine": "007800012345",
 "ansible_nodename": "MYLPAR",
 "ansible_os_family": "OS400",
 "ansible_pkg_mgr": "unknown",
 "ansible_python": {
 "executable": "/QOpenSys/pkgs/bin/python2",
 "has_sslcontext": true,
 "type": "CPython",
 "version": {
 "major": 2,
 "micro": 18,
 "minor": 7,
 "releaselevel": "final",
"serial": 0
 },
 "version_info": [
 2,
 7,
 18,
 "final",
 0
 ]
 },
 "ansible_python_version": "2.7.18",
 "ansible_real_group_id": 0,
 "ansible_real_user_id": 485,
 "ansible_selinux": {
 "status": "Missing selinux Python library"
 },
 "ansible_selinux_python_present": false,
 "ansible_service_mgr": "service",
 "ansible_system": "OS400",
 "ansible_user_dir": "/home/grobinso",
 "ansible_user_gecos": "",
 "ansible_user_gid": 0,
 "ansible_user_id": "grobinso",
 "ansible_user_shell": "/QOpenSys/pkgs/bin/bash",
 "ansible_user_uid": 485,
 "ansible_userspace_bits": "64",
 "ansible_virtualization_role": "",
 "ansible_virtualization_type": "",
 "gather_subset": [
 "all"
 ],
 "module_setup": true
 },
 "changed": false
}
LiJunBJZhu commented 3 years ago

After setting up open source on IBM i, yum is not added to $PATH by default.

Below is a workaround

‘’‘ tasks:

robinsg commented 3 years ago

Thanks for that.

I have managed to get around this by doing the following:

- name: Update packages
  yum:
    name: "*"
    state: present:
    use_backend: yum
  environment:
    PATH: "/QOpenSys/pkgs/bin://QOpenSys/usr/bin:/usr/ccs/bin:/QOpenSys/usr/bin/X11:/usr/sbin:.:/usr/bin"

The issue is that /QOpenSys/pkgs/bin is not in that path when Ansible connects to the system. When I log in via ssh /etc/profile is executed which prepends /QOpenSys/pkgs/bin to the PATH.

How can I add /QOpenSys/pkgs/bin to the path of all sessions?

I tried changing the PASE_PATH environment variable at the *SYS level but it didn't help.

LiJunBJZhu commented 3 years ago

Ansible isn't really doing things through the shell, it's transferring modules and executing scripts that it transfers, not using a login shell. It's not a continuous shell environment basically, nor is it logging in and typing commands and things.

In your cases, you may set an environment in your playbook, for example,

- name: Miscs
  hosts: all
  gather_facts: false
  collections:
    - ibm.power_ibmi

  environment:
    PATH: "/QOpenSys/pkgs/bin://QOpenSys/usr/bin:/usr/ccs/bin:/QOpenSys/usr/bin/X11:/usr/sbin:.:/usr/bin"

  tasks:
    - name: try yum
      command: yum --help

    - name: try rpm
      command: rpm --help
ravidsinghbiz commented 3 years ago

Just started using Ansible-on-i and ran into this issue. I got it working with @LiJunBJZhu solution to temporary switch python3 with python2 combined with @robinsg use_backend=yum