[stable-2.8] Don't warn if local user is found in user database (#56838)
If the 'local' parameter of the 'user' Ansible module is enabled, and
the user has been found in the local user database, don't emit
a warning, because this is an expected outcome.
Add changelog and integration tests
Co-authored-by: drybed <drybjed@gmail.com>
(cherry picked from commit 75be309242
)
Co-authored-by: Maciej Delmanowski <drybjed@drybjed.net>
This commit is contained in:
parent
e5759e587a
commit
703618336f
3 changed files with 20 additions and 6 deletions
2
changelogs/fragments/user-local-warning-fix.yaml
Normal file
2
changelogs/fragments/user-local-warning-fix.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- 'user - do not warn when using ``local: yes`` if user already exists (https://github.com/ansible/ansible/issues/58063)'
|
|
@ -863,9 +863,11 @@ class User(object):
|
|||
exists = True
|
||||
break
|
||||
|
||||
if not exists:
|
||||
self.module.warn(
|
||||
"'local: true' specified and user was not found in {file}. "
|
||||
"The local user account may already exist if the local account database exists somewhere other than {file}.".format(file=self.PASSWORDFILE))
|
||||
"'local: true' specified and user '{name}' was not found in {file}. "
|
||||
"The local user account may already exist if the local account database exists "
|
||||
"somewhere other than {file}.".format(file=self.PASSWORDFILE, name=self.name))
|
||||
|
||||
return exists
|
||||
|
||||
|
|
|
@ -829,6 +829,14 @@
|
|||
tags:
|
||||
- user_test_local_mode
|
||||
|
||||
- name: Create local account that already exists to check for warning
|
||||
user:
|
||||
name: root
|
||||
local: yes
|
||||
register: local_existing
|
||||
tags:
|
||||
- user_test_local_mode
|
||||
|
||||
- name: Create local_ansibulluser
|
||||
user:
|
||||
name: local_ansibulluser
|
||||
|
@ -909,10 +917,12 @@
|
|||
tags:
|
||||
- user_test_local_mode
|
||||
|
||||
- name: Ensure warnings were displayed
|
||||
- name: Ensure warnings were displayed properly
|
||||
assert:
|
||||
that:
|
||||
- local_user_test_1['warnings'] | length > 0
|
||||
- "'user was not found in /etc/passwd. The local user account may already exist if the local account
|
||||
database exists somewhere other than /etc/passwd.' in local_user_test_1['warnings'][0]"
|
||||
- local_user_test_1['warnings'] | first is search('The local user account may already exist')
|
||||
- local_existing['warnings'] is not defined
|
||||
when: ansible_facts.system in ['Linux']
|
||||
tags:
|
||||
- user_test_local_mode
|
||||
|
|
Loading…
Reference in a new issue