HewlettPackard / ilo-ansible-collection

Ansible Collection and Sample Playbooks for HPE iLO
Apache License 2.0
42 stars 22 forks source link

Redfish module issue in SNMP modules (Python3) #16

Closed Furius-Starfall closed 1 year ago

Furius-Starfall commented 1 year ago

Hi, I'm having issue with SNMP modules for iLOs. The issue seems to be in import redfish module, but also the issue can be between chair and monitor. Below are versions of Ansible, Python and Redfish.

ansible [core 2.13.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /bin/ansible
  python version = 3.9.13 (main, Nov  9 2022, 13:16:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
  jinja version = 3.1.2
  libyaml = True

python = 3.9.13
redfish = 3.1.9

Using following Playbook and inventory PLAYBOOK

---
- hosts: ilo
  connection: local
  gather_facts: False
  tasks:
  - name: Get SNMPv3 users
    hpe.ilo.get_snmpv3_users:
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
    register: result

  - name: SNMPv3 users in the server
    debug:
      msg: "{{ result }}"

INVENTORY

all:
  hosts:
  children:
    ilo:
      hosts:
        ilo-07:
          baseuri: 172.23.0.12
          username: **********
          password: **********
          http_schema: http

Issuing command ansible-playbook playbook-snmp.yml -i hosts.yaml returns

TASK [Get SNMPv3 users] *********************************************************************************************************************************************************************************************************************
fatal: [ilo-07]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "changed": false, "msg": "Failed to import the required Python library (redfish) on server's Python /usr/libexec/platform-python. 
Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}

Also I found that python3 is using different interprenter so i tried command _ansible-playbook playbook-snmp.yml -i hosts.yaml -e 'ansible_pythoninterpreter=/usr/bin/python3' -vvv

with output

ansible-playbook [core 2.13.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /bin/ansible-playbook
  python version = 3.9.13 (main, Nov  9 2022, 13:16:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
  jinja version = 3.1.2
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/osadmin/Ansible/hosts.yaml as it did not pass its verify_file() method
script declined parsing /home/osadmin/Ansible/hosts.yaml as it did not pass its verify_file() method
Skipping empty key (hosts) in group (all)
Parsed /home/osadmin/Ansible/hosts.yaml inventory source with yaml plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: playbook-snmp.yml *****************************************************************************************************************************************************************************************************************
1 plays in playbook-snmp.yml

PLAY [ilo] **********************************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [Get SNMPv3 users] *********************************************************************************************************************************************************************************************************************
task path: /home/osadmin/Ansible/playbook-snmp.yml:6
<ilo-07> ESTABLISH LOCAL CONNECTION FOR USER: root
<ilo-07> EXEC /bin/sh -c 'echo ~root && sleep 0'
<ilo-07> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563 `" && echo ansible-tmp-1681407231.5220683-390456-215541592781563="` echo /root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/hpe/ilo/plugins/modules/get_snmpv3_users.py
<ilo-07> PUT /root/.ansible/tmp/ansible-local-390452lfkrzhsi/tmpb2ds0kox TO /root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/AnsiballZ_get_snmpv3_users.py
<ilo-07> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/ /root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/AnsiballZ_get_snmpv3_users.py && sleep 0'
<ilo-07> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/AnsiballZ_get_snmpv3_users.py && sleep 0'
<ilo-07> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/AnsiballZ_get_snmpv3_users.py", line 107, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/AnsiballZ_get_snmpv3_users.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/AnsiballZ_get_snmpv3_users.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.hpe.ilo.plugins.modules.get_snmpv3_users', init_globals=dict(_module_fqn='ansible_collections.hpe.ilo.plugins.modules.get_snmpv3_users', _modlib_path=modlib_path),
  File "/usr/lib64/python3.9/runpy.py", line 225, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_hpe.ilo.get_snmpv3_users_payload_tp58ny7l/ansible_hpe.ilo.get_snmpv3_users_payload.zip/ansible_collections/hpe/ilo/plugins/modules/get_snmpv3_users.py", line 196, in <module>
  File "/tmp/ansible_hpe.ilo.get_snmpv3_users_payload_tp58ny7l/ansible_hpe.ilo.get_snmpv3_users_payload.zip/ansible_collections/hpe/ilo/plugins/modules/get_snmpv3_users.py", line 187, in main
  File "/usr/local/lib/python3.9/site-packages/redfish/rest/v1.py", line 978, in login
    raise SessionCreationError('HTTP {}: Failed to created the session\n{}'.format(resp.status, error_str))
redfish.rest.v1.SessionCreationError: HTTP 400: Failed to created the session
See @Message.ExtendedInfo for more information.
fatal: [ilo-07]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/AnsiballZ_get_snmpv3_users.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/AnsiballZ_get_snmpv3_users.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1681407231.5220683-390456-215541592781563/AnsiballZ_get_snmpv3_users.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.hpe.ilo.plugins.modules.get_snmpv3_users', init_globals=dict(_module_fqn='ansible_collections.hpe.ilo.plugins.modules.get_snmpv3_users', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.9/runpy.py\", line 225, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_hpe.ilo.get_snmpv3_users_payload_tp58ny7l/ansible_hpe.ilo.get_snmpv3_users_payload.zip/ansible_collections/hpe/ilo/plugins/modules/get_snmpv3_users.py\", line 196, in <module>\n  File \"/tmp/ansible_hpe.ilo.get_snmpv3_users_payload_tp58ny7l/ansible_hpe.ilo.get_snmpv3_users_payload.zip/ansible_collections/hpe/ilo/plugins/modules/get_snmpv3_users.py\", line 187, in main\n  File \"/usr/local/lib/python3.9/site-packages/redfish/rest/v1.py\", line 978, in login\n    raise SessionCreationError('HTTP {}: Failed to created the session\\n{}'.format(resp.status, error_str))\nredfish.rest.v1.SessionCreationError: HTTP 400: Failed to created the session\nSee @Message.ExtendedInfo for more information.\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
ilo-07                     : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
TSKushal commented 1 year ago

Have you run the following commands before execution? pip3 install ansible==4.5.0 ansible-core==2.11.5 pip3 install redfish==3.0.2

These are required steps before running the scripts.

Furius-Starfall commented 1 year ago

Hi, I thought that these are minimum required versions. Now it's working as it should. Thank you for helping me.