Bug 1747413

Summary: [ansible-freeipa] user module throwing an error if there are no changes to apply
Product: Red Hat Enterprise Linux 8 Reporter: Varun Mylaraiah <mvarun>
Component: ansible-freeipaAssignee: Thomas Woerner <twoerner>
Status: CLOSED ERRATA QA Contact: ipa-qe <ipa-qe>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.1CC: ksiddiqu, pcech
Target Milestone: rc   
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: ansible-freeipa-0.1.8-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-04-28 16:01:56 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Varun Mylaraiah 2019-08-30 11:24:16 UTC
Description of problem:
Seeing error while creating an existing user with no changes.


Version-Release number of selected component (if applicable):
ansible-freeipa-0.1.6-3.el8.noarch


Steps to Reproduce:
# cat add-user.yml
---
- name: Playbook to handle users
  hosts: ipaserver
  become: true

  tasks:
  - ipauser:
      ipaadmin_principal: admin
      ipaadmin_password: <xxxx>
      name: testuser
      first: testuser
      last: First_test
      title: test_title
      uid: 10002
      gid: 101
      phone: "+445123457"
      email: testuser4
      passwordexpiration: "2023-01-19 23:59:59"
      password: "no-password"
      update_password: on_create



# ansible-playbook -vv -i inventory/hosts.server add-user.yml 
ansible-playbook 2.8.4
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.6.8 (default, Aug  6 2019, 19:43:07) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]
No config file found; using defaults

PLAYBOOK: add-user.yml **********************************************************************************************
1 plays in add-user.yml

PLAY [Playbook to handle users] *************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
task path: /root/add-user.yml:2
ok: [ipaserver.test.local]
META: ran handlers

TASK [ipauser] ******************************************************************************************************
task path: /root/add-user.yml:7
changed: [ipaserver.test.local] => {"changed": true}
META: ran handlers
META: ran handlers

PLAY RECAP **********************************************************************************************************
ipaserver.test.local       : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

# cat add-user.yml
---
- name: Playbook to handle users
  hosts: ipaserver
  become: true

  tasks:
  - ipauser:
      ipaadmin_principal: admin
      ipaadmin_password: <xxxx>
      name: testuser
      first: testuser
      last: First_test
      title: test_title
      uid: 10002
      gid: 101
      phone: "+445123457"
      email: testuser4
      passwordexpiration: "2023-01-19 23:59:59"
      password: "no-password"
      update_password: on_create


# ansible-playbook -vv -i inventory/hosts.server add-user.yml 
ansible-playbook 2.8.4
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.6.8 (default, Aug  6 2019, 19:43:07) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]
No config file found; using defaults

PLAYBOOK: add-user.yml **********************************************************************************************
1 plays in add-user.yml

PLAY [Playbook to handle users] *************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
task path: /root/add-user.yml:2
ok: [ipaserver.test.local]
META: ran handlers

TASK [ipauser] ******************************************************************************************************
task path: /root/add-user.yml:7
fatal: [ipaserver.test.local]: FAILED! => {"changed": false, "msg": "user_mod: no modifications to be performed"}

PLAY RECAP **********************************************************************************************************
ipaserver.test.local       : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


with ansible-playbook -vvv
==========================
The full traceback is:
  File "/tmp/ansible_ipauser_payload_5ba8gh9n/ansible_ipauser_payload.zip/ansible/module_utils/ansible_freeipa_module.py", line 99, in api_command
    return api.Command[command](name, **args)
  File "/usr/lib/python3.6/site-packages/ipalib/frontend.py", line 450, in __call__
    return self.__do_call(*args, **options)
  File "/usr/lib/python3.6/site-packages/ipalib/frontend.py", line 478, in __do_call
    ret = self.run(*args, **options)
  File "/usr/lib/python3.6/site-packages/ipalib/frontend.py", line 800, in run
    return self.execute(*args, **options)
  File "/usr/lib/python3.6/site-packages/ipaserver/plugins/baseldap.py", line 1477, in execute
    raise e
  File "/usr/lib/python3.6/site-packages/ipaserver/plugins/baseldap.py", line 1474, in execute
    self._exc_wrapper(keys, options, ldap.update_entry)(update)
  File "/usr/lib/python3.6/site-packages/ipaserver/plugins/baseldap.py", line 1107, in wrapped
    return func(*call_args, **call_kwargs)
  File "/usr/lib/python3.6/site-packages/ipaserver/plugins/baseldap.py", line 1116, in exc_func
    self, keys, options, e, call_func, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/ipaserver/plugins/baseldap.py", line 1519, in exc_callback
    raise exc
  File "/usr/lib/python3.6/site-packages/ipaserver/plugins/baseldap.py", line 1107, in wrapped
    return func(*call_args, **call_kwargs)
  File "/usr/lib/python3.6/site-packages/ipapython/ipaldap.py", line 1691, in update_entry
    raise errors.EmptyModlist()

fatal: [ipaserver.test.local]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "displayname": null,
            "email": [
                "testuser4"
            ],
            "first": "testuser",
            "fullname": null,
            "gid": 101,
            "homedir": null,
            "ipaadmin_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "ipaadmin_principal": "admin",
            "last": "First_test",
            "name": [
                "testuser"
            ],
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "passwordexpiration": "2023-01-19 23:59:59",
            "phone": [
                "+445123457"
            ],
            "preserve": null,
            "principalname": null,
            "shell": null,
            "state": "present",
            "title": "test_title",
            "uid": 10002,
            "update_password": "on_create"
        }
    },
    "msg": "user_mod: no modifications to be performed"
}


Actual results:
Falling if there are no changes to be applied

Expected results:
If there are no changes to be applied, then the module will simply succeed 

Additional info:

Comment 2 Thomas Woerner 2019-12-14 06:59:27 UTC
This is the upstream PR for this:

- https://github.com/freeipa/ansible-freeipa/commit/bc3d3f41396f3b2c49a352ef8eb1f68f35b31672
  ipauser: Extend email addresses with default email domain if no domain is set

It also needs this:

- https://github.com/freeipa/ansible-freeipa/commit/0210899eb7187e5d70b490455647cb2bb595169a
  Allow execution of API commands that do not require a name.

Comment 4 Varun Mylaraiah 2020-02-14 07:18:47 UTC
Verified 
ansible-freeipa-0.1.8-1.el8.noarch

cat add-user.yaml
---
- name: Playbook to handle users
  hosts: ipaserver
  become: true

  tasks:
  - ipauser:
      ipaadmin_principal: admin
      ipaadmin_password: <xxxx>
      name: testuser
      first: testuser
      last: First_test
      title: test_title
      uid: 10002
      gid: 101
      phone: "+445123457"
      email: testuser4
      passwordexpiration: "2023-01-19 23:59:59"
      password: "no-password"
      update_password: on_create


# ansible-playbook -vv -i inventory/server.hosts add-user.yaml 
ansible-playbook 2.9.4
  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.6/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.6.8 (default, Dec  5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: add-user.yaml **********************************************************************************************
1 plays in add-user.yaml

PLAY [Playbook to handle users] **************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************
task path: /root/add-user.yaml:2
ok: [master.ipadomain.test]
META: ran handlers

TASK [ipauser] *******************************************************************************************************
task path: /root/add-user.yaml:7
changed: [master.ipadomain.test] => {"changed": true, "user": {}}
META: ran handlers
META: ran handlers

PLAY RECAP ***********************************************************************************************************
master.ipadomain.test      : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   


# cat add-user.yaml
---
- name: Playbook to handle users
  hosts: ipaserver
  become: true

  tasks:
  - ipauser:
      ipaadmin_principal: admin
      ipaadmin_password: <xxxx>
      name: testuser
      first: testuser
      last: First_test
      title: test_title
      uid: 10002
      gid: 101
      phone: "+445123457"
      email: testuser4
      passwordexpiration: "2023-01-19 23:59:59"
      password: "no-password"
      update_password: on_create
      
[root@ansible ~]# ansible-playbook -vv -i inventory/server.hosts add-user.yaml 
ansible-playbook 2.9.4
  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.6/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.6.8 (default, Dec  5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: add-user.yaml **********************************************************************************************
1 plays in add-user.yaml

PLAY [Playbook to handle users] **************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************
task path: /root/add-user.yaml:2
ok: [master.ipadomain.test]
META: ran handlers

TASK [ipauser] *******************************************************************************************************
task path: /root/add-user.yaml:7
ok: [master.ipadomain.test] => {"changed": false, "user": {}}
META: ran handlers
META: ran handlers

PLAY RECAP ***********************************************************************************************************
master.ipadomain.test      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

No traceback while adding the same user again.
Based on the above observation, marking the bug VERIFIED

Comment 6 errata-xmlrpc 2020-04-28 16:01:56 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:1705