ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
836 stars 1.53k forks source link

Not able configure hostname in redfish #5892

Open kotireddy478 opened 1 year ago

kotireddy478 commented 1 year ago

Summary

Hi,

I'm trying to configure ilo hostname using redfish config in https://github.com/HewlettPackard/ilo-ansible-collection/blob/main/roles/playbooks/Manager/config_hostname.yml but i'm getting below error. Could you please help?

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'ret'
fatal: [host_name]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/ansible/.ansible/tmp/ansible-tmp-1674659669.5978777-8741-211049437950632/AnsiballZ_redfish_config.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/home/ansible/.ansible/tmp/ansible-tmp-1674659669.5978777-8741-211049437950632/AnsiballZ_redfish_config.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/username/.ansible/tmp/ansible-tmp-1674659669.5978777-8741-211049437950632/AnsiballZ_redfish_config.py\", line 41, in invoke_module\n    run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python2.7/runpy.py\", line 176, in run_module\n    fname, loader, pkg_name)\n  File \"/usr/lib64/python2.7/runpy.py\", line 82, in _run_module_code\n    mod_name, mod_fname, mod_loader, pkg_name)\n  File \"/usr/lib64/python2.7/runpy.py\", line 72, in _run_code\n    exec code in run_globals\n  File \"/tmp/ansible_community.general.redfish_config_payload_ob0p90/ansible_community.general.redfish_config_payload.zip/ansible_collections/community/general/plugins/modules/redfish_config.py\", line 389, in <module>\n  File \"/tmp/ansible_community.general.redfish_config_payload_ob0p90/ansible_community.general.redfish_config_payload.zip/ansible_collections/community/general/plugins/modules/redfish_config.py\", line 379, in main\nKeyError: 'ret'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Thanks

Issue Type

Bug Report

Component Name

community.general.redfish_config

Ansible Version

$ ansible --version
ansible [core 2.11.12] 

Community.general Version

$ ansible-galaxy collection list community.general
community.general 4.8.1  

Configuration

$ ansible-config dump --only-changed

OS / Environment

CentOS 7

Steps to Reproduce

 https://github.com/HewlettPackard/ilo-ansible-collection/blob/main/roles/playbooks/Manager/config_hostname.yml 

Expected Results

I expected hostname removed to passed var

Actual Results

Code of Conduct

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 1 year ago

cc @bhavya06 @mraineri @rajeevkallur @renxulei @tomasg2012 @xmadsen click here for bot help

mraineri commented 1 year ago

Running the same request with a stripped down playbook seems to work okay for me. Will need to experiment with your exact playbook.

I also see you're using an older version of the module; would you be able to try the latest version (6.2)?

Here's my reduced playbook for reference:

---
- hosts: all
  gather_facts: false
  vars:
    username: <REDACTED>
    password: <REDACTED>
    baseuri: <REDACTED>
    default_uri_timeout: 40
    default_uri_retries: 5
    attribute_value: <REDACTED>
  tasks:
  - name: Set Manager NIC
    community.general.redfish_config:
      category: Manager
      command: SetManagerNic
      baseuri: "{{ baseuri }}"
      username: "{{ username }}"
      password: "{{ password }}"
      nic_config:
        HostName: "{{ attribute_value }}"
    retries: "{{ default_uri_retries }}"
    timeout: "{{ default_uri_timeout }}"
    register: redfish_results
  - debug:
      var: redfish_results
mraineri commented 1 year ago

Downgraded on my end to 4.8.1 and the above playbook still works... Will keep digging...

mraineri commented 1 year ago

Still not recreating the issue with this playbook:

---
- hosts: all
  name: Configure HostName
  gather_facts: False
  # vars_files: iLO_redfish.yml

  vars:
    - attribute_name: HostName
    - attribute_value: <REDACTED>
    - username: <REDACTED>
    - password: <REDACTED>
    - baseuri: <REDACTED>

  tasks:
    - name: Create session
      community.general.redfish_command:
        category: Sessions
        command: CreateSession
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
      register: result

    - name: Set Manager NIC
      community.general.redfish_config:
        category: Manager
        command: SetManagerNic
        nic_config:
          HostName: "{{ attribute_value }}"
        baseuri: "{{ baseuri }}"
        # username: "{{ username }}"
        # password: "{{ password }}"
        auth_token: "{{ result.session.token }}"

    - name: Delete session using security token created by CreateSesssion above
      community.general.redfish_command:
        category: Sessions
        command: DeleteSession
        baseuri: "{{ baseuri }}"
        auth_token: "{{ result.session.token }}"
        session_uri: "{{ result.session.uri }}"
kotireddy478 commented 1 year ago

Hi - Thanks for all investigation.

I tried with latest version (6.2) but it's also failing.

Little bit of background info:

We have a host called pp-ilo-ilo1.example.com and our Ansible inventory hostname is also the same. To test host renaming, we changed the hostname to pp-ilo-ilo6.example.com and running the playbook to rename back to pp-ilo-ilo1.example.com but unfortunately it's not working. Ansible inventory with ilo ip address working but not host name. I hope it makes sense to you.

Thanks

kotireddy478 commented 1 year ago

Still not recreating the issue with this playbook:

---
- hosts: all
  name: Configure HostName
  gather_facts: False
  # vars_files: iLO_redfish.yml

  vars:
    - attribute_name: HostName
    - attribute_value: <REDACTED>
    - username: <REDACTED>
    - password: <REDACTED>
    - baseuri: <REDACTED>

  tasks:
    - name: Create session
      community.general.redfish_command:
        category: Sessions
        command: CreateSession
        baseuri: "{{ baseuri }}"
        username: "{{ username }}"
        password: "{{ password }}"
      register: result

    - name: Set Manager NIC
      community.general.redfish_config:
        category: Manager
        command: SetManagerNic
        nic_config:
          HostName: "{{ attribute_value }}"
        baseuri: "{{ baseuri }}"
        # username: "{{ username }}"
        # password: "{{ password }}"
        auth_token: "{{ result.session.token }}"

    - name: Delete session using security token created by CreateSesssion above
      community.general.redfish_command:
        category: Sessions
        command: DeleteSession
        baseuri: "{{ baseuri }}"
        auth_token: "{{ result.session.token }}"
        session_uri: "{{ result.session.uri }}"

To replicate this try changing hostname from ILOSGH924TZ37 to a name say ILOSGH924TZ38 and then try to change back to ILOSGH924TZ37. You will see the error we were getting. Please let me know if you need any additional info.

mraineri commented 1 year ago

Thanks; I'll see if I can track down an HPE system. Maybe it's an issue where the request is failing, and is exposing a bug in the module. If I can't find an HPE system I might be able to set up a mockup and force errors and other issues that could trigger the exception...

ansibullbot commented 1 year ago

cc @TSKushal click here for bot help

ansibullbot commented 1 year ago

cc @jyundt click here for bot help

mraineri commented 1 year ago

@kotireddy478 sorry about the delay for digging further into this; I was able to access an HPE system and still not able to recreate the issue... I can attempt to create mockups to force various error paths as a next step to see what could be going on... If that's not successful, would you be willing to run things out of a debug branch to trace down what's happening for you?

mraineri commented 1 year ago

I was also able to stimulate an error path with a bad hostname, but it looks like it's being handled properly:

TASK [Set Manager NIC] *******************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "HTTP Error 400 on PATCH request to 'https://<REDACTED>/redfish/v1/Managers/1/EthernetInterfaces/1/', extended message: '[{'MessageArgs': ['<REDACTED>', 'HostName'], 'MessageId': 'Base.1.4.PropertyValueFormatError'}]'"}
mraineri commented 1 year ago

And for clarity... In the baseuri field of the playbook, are you using the IP address of the iLO or something else?

a-dawg commented 7 months ago

+1 with community.general 8.5.0 cannot set hostname on hpe gen11 either also see: https://github.com/HewlettPackard/ilo-ansible-collection/issues/22