HewlettPackard / oneview-ansible

This project is no longer being developed and has limited support. Please use the newer Ansible Collection project: https://github.com/HewlettPackard/oneview-ansible-collection
Apache License 2.0
104 stars 65 forks source link

An exception is returned after user permission assignment #679

Closed bigmagic closed 3 years ago

bigmagic commented 3 years ago

Scenario/Intent

The SDK should be able to assign a permission to a user.

Environment Details

Steps to Reproduce

You will find below a playbook to reproduce the issue:

- hosts: localhost    
  vars:
    config: "oneview.json"
    ansible_python_interpreter: "/usr/local/bin/python3.6"
    scopeName: "ScopeTest"
    userName: admin-test
    password: "admin12345"
    roleName: "Infrastructure administrator"
    emailAddress: "email@test.fr"
    permissions: [ ]

  tasks:

    - name: "Create a scope"
      oneview_scope:
        config: "{{ config }}"
        state: present
        data:
          name: "{{ scopeName }}"

    - name: "Get scope"
      oneview_scope_facts:
        config: "{{ config }}"
        name: "{{ scopeName }}"

    - debug: var=scopes[0].uri

    - name: "Get User"
      oneview_user_facts:
        config: "{{ config }}"

    - name: "Fact"
      set_fact:
        __permissions: [ {
            roleName: "{{ roleName }}",
            scopeUri: "{{ scopes[0].uri }}"
            }
          ]

    - name: Update Permissions
      oneview_user:
        config: "{{ config }}"
        state: present
        data:
          userName: "{{ userName }}"
          password: "{{ password }}"
          emailAddress: "{{ emailAddress }}"
          enabled: true
          description: null
          mobilePhone: ""
          officePhone: ""
          fullName: "admin User"
          permissions: "{{ __permissions }}"

The user is created but the following exception is returned :

root@289e12e75de2:/playbooks# ansible-playbook scope-user-perm.yml
 [WARNING]: Found both group and host with same name: localhost

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

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

TASK [Create a scope] ***************************************************************************************************************************
ok: [localhost]

TASK [Get scope] ********************************************************************************************************************************
ok: [localhost]

TASK [debug] ************************************************************************************************************************************
ok: [localhost] => {
    "scopes[0].uri": "/rest/scopes/f2fe231b-c130-46c6-8dc2-034907ea1204"
}

TASK [Get User] *********************************************************************************************************************************
ok: [localhost]

TASK [Fact] *************************************************************************************************************************************
ok: [localhost]

TASK [Update Permissions] ***********************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: Value of unknown type: <class 'hpeOneView.resources.security.users.Users'>, <hpeOneView.resources.security.users.Users object at 0x7fd5b57bba20>
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1618822111.4147062-272120607855560/AnsiballZ_oneview_user.py\", line 113, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1618822111.4147062-272120607855560/AnsiballZ_oneview_user.py\", line 105, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1618822111.4147062-272120607855560/AnsiballZ_oneview_user.py\", line 48, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/usr/local/lib/python3.6/imp.py\", line 235, in load_module\n    return load_source(name, filename, file)\n  File \"/usr/local/lib/python3.6/imp.py\", line 170, in load_source\n    module = _exec(spec, sys.modules[name])\n  File \"<frozen importlib._bootstrap>\", line 618, in _exec\n  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n  File \"/tmp/ansible_oneview_user_payload_wcyx0dof/__main__.py\", line 182, in <module>\n  File \"/tmp/ansible_oneview_user_payload_wcyx0dof/__main__.py\", line 178, in main\n  File \"/tmp/ansible_oneview_user_payload_wcyx0dof/ansible_oneview_user_payload.zip/ansible/module_utils/oneview.py\", line 776, in run\n  File \"/tmp/ansible_oneview_user_payload_wcyx0dof/ansible_oneview_user_payload.zip/ansible/module_utils/basic.py\", line 2348, in exit_json\n  File \"/tmp/ansible_oneview_user_payload_wcyx0dof/ansible_oneview_user_payload.zip/ansible/module_utils/basic.py\", line 2341, in _return_formatted\n  File \"/tmp/ansible_oneview_user_payload_wcyx0dof/ansible_oneview_user_payload.zip/ansible/module_utils/basic.py\", line 522, in remove_values\n  File \"/tmp/ansible_oneview_user_payload_wcyx0dof/ansible_oneview_user_payload.zip/ansible/module_utils/basic.py\", line 505, in _remove_values_conditions\nTypeError: Value of unknown type: <class 'hpeOneView.resources.security.users.Users'>, <hpeOneView.resources.security.users.Users object at 0x7fd5b57bba20>\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
        to retry, use: --limit @/playbooks/scope-user-perm.retry

PLAY RECAP **************************************************************************************************************************************
localhost                  : ok=6    changed=0    unreachable=0    failed=1

Expected Result

Permissions correctly handled by the SDK.

Actual Result

An exception is returned by the SDK

Best Regards, Nicolas

SHANDCRUZ commented 3 years ago

Hi @bigmagic currently we are not supporting users resource. we will take this as an enhancement request and will extend our support to this resource also.

bigmagic commented 3 years ago

Perfect. I thank you.

SHANDCRUZ commented 3 years ago

Hi @bigmagic the support for User resource has been added and also updated examples are merged into master branch. Please feel free to reopen if further help needed.