diff options
author | MajesticMagikarpKing <69774548+yctomwang@users.noreply.github.com> | 2024-07-07 21:26:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-07 21:26:14 +0200 |
commit | edce79871333d2d3d4812a5c74e974a58eeaffb3 (patch) | |
tree | 8cfd203409fe01bb8ad2fe82d889585912039d25 | |
parent | validate-modules: reject option/alias names equal up to casing belonging to d... (diff) | |
download | ansible-edce79871333d2d3d4812a5c74e974a58eeaffb3.tar.xz ansible-edce79871333d2d3d4812a5c74e974a58eeaffb3.zip |
Fix Creating user directory using tilde always reports "changed" (#83113)
Fixes: #82490
3 files changed, 30 insertions, 2 deletions
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 0000000000..f7abc1335c --- /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 701f62d3b2..a25b29eaf5 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 644dbebbc5..44707dc7fb 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 |