mirror of
https://github.com/ansible/ansible
synced 2026-06-19 07:35:52 +00:00
user: Warn if move_home is true and home dir does not exist (#87056)
* While modifying the user with lusermod command, warn user if home directory does not exists and move_home is set to true. Fixes: #37398 Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- user - warn if move_home is true and home directory does not exist (https://github.com/ansible/ansible/issues/37398).
|
||||
@@ -126,6 +126,7 @@ options:
|
||||
description:
|
||||
- "If set to V(true) when used with O(home), attempt to move the user's old home
|
||||
directory to the specified directory if it isn't there already and the old home exists."
|
||||
- If O(local) is set to V(true), this option will be ignored if the current home directory does not exist.
|
||||
type: bool
|
||||
default: no
|
||||
system:
|
||||
@@ -978,11 +979,15 @@ class User(object):
|
||||
cmd.append('-c')
|
||||
cmd.append(self.comment)
|
||||
|
||||
if self.home is not None and info[5] != self.home:
|
||||
existing_home = info[5]
|
||||
if self.home is not None and existing_home != self.home:
|
||||
cmd.append('-d')
|
||||
cmd.append(self.home)
|
||||
if self.move_home:
|
||||
cmd.append('-m')
|
||||
if self.local and not os.path.exists(existing_home):
|
||||
self.module.warn("Ignoring move_home since home directory %s does not exist, but local is true" % existing_home)
|
||||
else:
|
||||
cmd.append('-m')
|
||||
|
||||
if self.shell is not None and info[6] != self.shell:
|
||||
cmd.append('-s')
|
||||
|
||||
@@ -232,3 +232,41 @@
|
||||
force: yes
|
||||
remove: yes
|
||||
local: yes
|
||||
|
||||
- name: Test move_home for local users
|
||||
when: ansible_facts.system in ['Linux']
|
||||
block:
|
||||
- name: Create local_ansibulluser
|
||||
user:
|
||||
name: local_ansibulluser
|
||||
state: present
|
||||
local: yes
|
||||
createhome: false
|
||||
register: local_user_test_8
|
||||
|
||||
- name: Move home for local_ansibulluser
|
||||
user:
|
||||
name: local_ansibulluser
|
||||
state: present
|
||||
local: yes
|
||||
move_home: true
|
||||
home: /home/local_ansibulluser_move_home
|
||||
createhome: true
|
||||
register: local_user_test_9
|
||||
|
||||
- name: Check if warnings were displayed properly
|
||||
assert:
|
||||
that:
|
||||
- local_user_test_8.changed
|
||||
- local_user_test_9.changed
|
||||
- local_user_test_9.warnings is defined
|
||||
- local_user_test_9.warnings[0] is search("Ignoring move_home since")
|
||||
|
||||
always:
|
||||
- name: Clean up local_ansibulluser
|
||||
user:
|
||||
name: local_ansibulluser
|
||||
state: absent
|
||||
force: yes
|
||||
remove: yes
|
||||
local: yes
|
||||
|
||||
Reference in New Issue
Block a user