HewlettPackard / oneview-ansible-collection

Ansible Collection and Sample Playbooks for HPE OneView
Apache License 2.0
25 stars 22 forks source link

The OneView Ansible Collection doesn't permit to update user password #159

Closed bigmagic closed 2 years ago

bigmagic commented 2 years ago

Hi,

We are using OneView 6.1 and the latest OneView SDK Collection version 6.4.

We have an issue to update user password using the SDK: no modification is performed.

We have tested witth others SDK : It is working as expected using the POSH-HPOneView SDK and with also using the REST API.

Version used;

You will find below an example code:

- hosts: localhost
  vars:
    config: 'oneview.json'
    ansible_python_interpreter: '/usr/bin/python3.6'
    userName: "test-user"
    roleName: "Infrastructure administrator"
    password1: "LONG1234@passwd1234"
    password2: "password67654#AZEDF"

  collections:
    - hpe.oneview

  tasks:

    - name: "Create a user"
      hpe.oneview.oneview_user:
        config: "{{ config }}"
        state: present
        data:
          userName: "{{ userName }}"
          password: "{{ password1 }}"
          enabled: True
          fullName: "User Name"
          mobilePhone: "+33600000000"
          officePhone: "+33600000000"
          permissions:
            - roleName: "{{ roleName }}"

    - name: "Update User password"
      hpe.oneview.oneview_user:
        config: "{{ config }}"
        state: present
        data:
          userName: "{{ userName }}"
          password: "{{ password2 }}"

The update of the password returns an "User is already present" error message.

PLAY [localhost] ********************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************
ok: [localhost]

TASK [Create a user] ****************************************************************************************************************************************
changed: [localhost] => {"ansible_facts": {"user": {"category": "users", "created": "2021-11-22T15:01:23.226Z", "description": null, "eTag": "994312728", "emailAddress": "", "enabled": true, "fullName": "User Name", "mobilePhone": "+33600000000", "modified": "2021-11-22T15:01:23.226Z", "name": null, "officePhone": "+33600000000", "permissions": [{"roleName": "Infrastructure administrator", "scopeUri": null}], "state": null, "status": null, "type": "UserAndPermissions", "uri": "/rest/users/test-user", "userName": "test-user"}}, "changed": true, "msg": "User created successfully."}

TASK [Update User password] *********************************************************************************************************************************
ok: [localhost] => {"ansible_facts": {"user": {"category": "users", "created": "2021-11-22T15:01:23.226Z", "description": null, "eTag": "994312728", "emailAddress": "", "enabled": true, "fullName": "User Name", "mobilePhone": "+33600000000", "modified": "2021-11-22T15:01:23.226Z", "name": null, "officePhone": "+33600000000", "permissions": [{"roleName": "Infrastructure administrator", "scopeUri": null}], "state": null, "status": null, "type": "UserAndPermissions", "uri": "/rest/users/test-user", "userName": "test-user"}}, "changed": false, "msg": "User is already present."}

PLAY RECAP **************************************************************************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

As I can see into the source code: https://github.com/HewlettPackard/oneview-ansible-collection/blob/master/plugins/modules/oneview_user.py

The password field is removed line 330 :

            # remove password, it cannot be used in comparison
            if 'password' in merged_data:
                del merged_data['password']

The Ansible Collection SDK should be able to update the user password.

Best Regards, Nicolas Portais

chebroluharika commented 2 years ago

Hi @bigmagic , We have merged fix into master and please check if your requirement is satisfied.

bigmagic commented 2 years ago

Hi @chebroluharika Yes It is working. Thanks