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>
This commit is contained in:
Maciej Delmanowski 2019-07-31 18:14:22 +02:00 committed by Sam Doran
parent cb9ab42ab8
commit 75be309242
3 changed files with 20 additions and 6 deletions

View 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)'

View file

@ -869,9 +869,11 @@ class User(object):
exists = True
break
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))
if not exists:
self.module.warn(
"'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

View file

@ -872,6 +872,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
@ -952,10 +960,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