From edce79871333d2d3d4812a5c74e974a58eeaffb3 Mon Sep 17 00:00:00 2001 From: MajesticMagikarpKing <69774548+yctomwang@users.noreply.github.com> Date: Mon, 8 Jul 2024 05:26:14 +1000 Subject: [PATCH] Fix Creating user directory using tilde always reports "changed" (#83113) Fixes: #82490 --- ...dir_using_tilde_always_reports_changed.yml | 2 ++ lib/ansible/modules/user.py | 5 ++-- .../targets/user/tasks/test_create_user.yml | 25 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/82490_creating_user_dir_using_tilde_always_reports_changed.yml diff --git a/changelogs/fragments/82490_creating_user_dir_using_tilde_always_reports_changed.yml b/changelogs/fragments/82490_creating_user_dir_using_tilde_always_reports_changed.yml new file mode 100644 index 00000000000..f7abc1335c6 --- /dev/null +++ b/changelogs/fragments/82490_creating_user_dir_using_tilde_always_reports_changed.yml @@ -0,0 +1,2 @@ +bugfixes: + - fixed the issue of creating user directory using tilde(~) always reported "changed".(https://github.com/ansible/ansible/issues/82490) diff --git a/lib/ansible/modules/user.py b/lib/ansible/modules/user.py index 701f62d3b24..a25b29eaf56 100644 --- a/lib/ansible/modules/user.py +++ b/lib/ansible/modules/user.py @@ -74,7 +74,8 @@ options: Since Ansible 2.5, the default shell for non-system users on macOS is V(/bin/bash). - On other operating systems, the default shell is determined by the underlying tool invoked by this module. See Notes for a per platform list of invoked tools. - type: str + - From Ansible 2.18, the type is changed to I(path) from I(str). + type: path home: description: - Optionally set the user's home directory. @@ -3167,7 +3168,7 @@ def main(): groups=dict(type='list', elements='str'), comment=dict(type='str'), home=dict(type='path'), - shell=dict(type='str'), + shell=dict(type='path'), password=dict(type='str', no_log=True), login_class=dict(type='str'), password_expire_max=dict(type='int', no_log=False), diff --git a/test/integration/targets/user/tasks/test_create_user.yml b/test/integration/targets/user/tasks/test_create_user.yml index 644dbebbc55..44707dc7fbe 100644 --- a/test/integration/targets/user/tasks/test_create_user.yml +++ b/test/integration/targets/user/tasks/test_create_user.yml @@ -77,3 +77,28 @@ that: - "'RealName: ansibulluser' in user_test2.stdout_lines " - "'PrimaryGroupID: 20' in user_test2.stdout_lines " + +#https://github.com/ansible/ansible/issues/82490 +- name: Create a new user with custom shell to test ~ expansion + user: + name: randomuserthomas + shell: ~/custom_shell + register: user_create_result + +- name: Create a new user with custom shell to test ~ expansion second time should show ok not changed + user: + name: randomuserthomas + shell: ~/custom_shell + register: user_creation_result + +- name: Assert that the user with a tilde in the shell path is created + assert: + that: + - user_creation_result is not changed + - user_create_result is changed + +- name: remove the randomuserthomas user to clean up + user: + name: randomuserthomas + state: absent + force: true \ No newline at end of file