[stable-2.18] - script fix become on Windows (#85077)

Fixes become when using script on Windows and the become options were
set through host vars or sources that was not set on the task directives
itself.
pull/85090/head
Jordan Borean 7 months ago committed by GitHub
parent 9b89ff86a4
commit 59e2ddcae0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,4 @@
bugfixes:
- >-
script - Fix up become support for Windows scripts when become was set through host variables and not on the task
directly - https://github.com/ansible/ansible/issues/85076

@ -150,11 +150,23 @@ class ActionModule(ActionBase):
# like become and environment args
if getattr(self._connection._shell, "_IS_WINDOWS", False):
# FUTURE: use a more public method to get the exec payload
pc = self._task
become = False
become_method = None
become_user = None
become_pass = None
become_flags = None
if self._connection.become:
become_plugin = self._connection.become
become = True
become_method = become_plugin.name
become_user = become_plugin.get_option('become_user', playcontext=self._play_context)
become_pass = become_plugin.get_option('become_pass', playcontext=self._play_context)
become_flags = become_plugin.get_option('become_flags', playcontext=self._play_context)
exec_data = ps_manifest._create_powershell_wrapper(
to_bytes(script_cmd), source, {}, env_dict, self._task.async_val,
pc.become, pc.become_method, pc.become_user,
self._play_context.become_pass, pc.become_flags, "script", task_vars, None
become, become_method, become_user,
become_pass, become_flags, "script", task_vars, None
)
# build the necessary exec wrapper command
# FUTURE: this still doesn't let script work on Windows with non-pipelined connections or

@ -314,3 +314,17 @@
that:
- test_script_result_become.stdout_lines[0]|lower == 'nt authority\\system'
- test_script_result_become.stdout_lines[1] == 'finished'
- name: run test script with become set by vars
script: test_script_whoami.ps1
register: test_script_result_become_vars
vars:
ansible_become: yes
ansible_become_user: SYSTEM
ansible_become_method: runas
- name: check that the script ran and we get both outputs on new lines
assert:
that:
- test_script_result_become_vars.stdout_lines[0]|lower == 'nt authority\\system'
- test_script_result_become_vars.stdout_lines[1] == 'finished'

Loading…
Cancel
Save