diff --git a/changelogs/fragments/68310-low_level_execute_command-honor-executable.yml b/changelogs/fragments/68310-low_level_execute_command-honor-executable.yml new file mode 100644 index 00000000000..2cc5e6b0f7e --- /dev/null +++ b/changelogs/fragments/68310-low_level_execute_command-honor-executable.yml @@ -0,0 +1,2 @@ +bugfixes: +- Update ActionBase._low_level_execute_command to honor executable (https://github.com/ansible/ansible/issues/68054) diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 8b309a0b1dc..9f96848503e 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -1053,6 +1053,10 @@ class ActionBase(with_metaclass(ABCMeta, object)): display.debug("_low_level_execute_command(): changing cwd to %s for this command" % chdir) cmd = self._connection._shell.append_command('cd %s' % chdir, cmd) + # https://github.com/ansible/ansible/issues/68054 + if executable: + self._connection._shell.executable = executable + ruser = self._get_remote_user() buser = self.get_become_option('become_user') if (sudoable and self._connection.become and # if sudoable and have become diff --git a/test/integration/targets/raw/runme.sh b/test/integration/targets/raw/runme.sh new file mode 100755 index 00000000000..079554277be --- /dev/null +++ b/test/integration/targets/raw/runme.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -ux +export ANSIBLE_BECOME_ALLOW_SAME_USER=1 +export ANSIBLE_ROLES_PATH=../ +ansible-playbook -i ../../inventory runme.yml -e "output_dir=${OUTPUT_DIR}" -v "$@" diff --git a/test/integration/targets/raw/runme.yml b/test/integration/targets/raw/runme.yml new file mode 100644 index 00000000000..ea865bcafb8 --- /dev/null +++ b/test/integration/targets/raw/runme.yml @@ -0,0 +1,4 @@ +- hosts: testhost + gather_facts: no + roles: + - { role: raw } diff --git a/test/integration/targets/raw/tasks/main.yml b/test/integration/targets/raw/tasks/main.yml index 715e4eb8023..7f99eadf278 100644 --- a/test/integration/targets/raw/tasks/main.yml +++ b/test/integration/targets/raw/tasks/main.yml @@ -81,3 +81,27 @@ - 'raw_result2.stdout_lines is defined' - 'raw_result2.rc == 0' - 'raw_result2.stdout_lines == ["foobar"]' +# the following five tests added to test https://github.com/ansible/ansible/pull/68315 +- name: get the path to sh + shell: which sh + register: sh_path +- name: use sh + raw: echo $0 + args: + executable: "{{ sh_path.stdout }}" + become: true + become_method: su + register: sh_output +- name: assert sh + assert: + that: "(sh_output.stdout | trim) == sh_path.stdout" +- name: use bash + raw: echo $0 + args: + executable: "{{ bash_path.stdout }}" + become: true + become_method: su + register: bash_output +- name: assert bash + assert: + that: "(bash_output.stdout | trim) == bash_path.stdout"