diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py index 38a58ca224..009eb06c48 100644 --- a/lib/ansible/executor/module_common.py +++ b/lib/ansible/executor/module_common.py @@ -826,7 +826,7 @@ def _find_module_utils(module_name, b_module_data, module_path, module_args, tas become_required = True for m in set(module_names): - m = to_text(m) + m = to_text(m).rstrip() # tolerate windows line endings mu_path = ps_module_utils_loader.find_plugin(m, ".psm1") if not mu_path: raise AnsibleError('Could not find imported module support code for \'%s\'.' % m) diff --git a/test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1 b/test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1 new file mode 100644 index 0000000000..d9c2e00825 --- /dev/null +++ b/test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1 @@ -0,0 +1,6 @@ +#!powershell + +#Requires -Module Ansible.ModuleUtils.Legacy + +Exit-Json @{ data="success" } + diff --git a/test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1 b/test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1 new file mode 100644 index 0000000000..d5d328a5d8 --- /dev/null +++ b/test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1 @@ -0,0 +1,4 @@ +#!powershell +# POWERSHELL_COMMON + +Exit-Json @{ data="success" } diff --git a/test/integration/targets/win_module_utils/tasks/main.yml b/test/integration/targets/win_module_utils/tasks/main.yml index 4b32cecfff..8f4ba6f851 100644 --- a/test/integration/targets/win_module_utils/tasks/main.yml +++ b/test/integration/targets/win_module_utils/tasks/main.yml @@ -14,6 +14,22 @@ that: - new_way.data == 'success' +- name: call old WANTS_JSON module with windows line endings + legacy_only_old_way_win_line_ending: + register: old_way_win + +- assert: + that: + - old_way_win.data == 'success' + +- name: call module with only legacy requires and windows line endings + legacy_only_new_way_win_line_ending: + register: new_way_win + +- assert: + that: + - new_way_win.data == 'success' + - name: call module with local module_utils uses_local_utils: register: local_utils diff --git a/test/sanity/code-smell/line-endings.py b/test/sanity/code-smell/line-endings.py index 1c2631889e..85b8109e4a 100755 --- a/test/sanity/code-smell/line-endings.py +++ b/test/sanity/code-smell/line-endings.py @@ -8,6 +8,8 @@ def main(): 'test/integration/targets/template/files/foo.dos.txt', 'test/integration/targets/win_regmerge/templates/win_line_ending.j2', 'test/integration/targets/win_template/files/foo.dos.txt', + 'test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1', + 'test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1', ]) for path in sys.argv[1:] or sys.stdin.read().splitlines(): diff --git a/test/sanity/code-smell/shebang.py b/test/sanity/code-smell/shebang.py index b61cd672b2..bac373bc45 100755 --- a/test/sanity/code-smell/shebang.py +++ b/test/sanity/code-smell/shebang.py @@ -25,6 +25,8 @@ def main(): skip = set([ 'hacking/cherrypick.py', + 'test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1', + 'test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1', ]) for path in sys.argv[1:] or sys.stdin.read().splitlines():