summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrwagnergit <rjwagner.commerce@gmail.com>2020-04-22 12:56:35 -0400
committerMatt Clay <matt@mystile.com>2020-05-05 21:16:09 -0700
commit081ce0e4e132a855550772379eedd7ae1be5335a (patch)
tree8bdb85a76ba440f346b24785f532fb89fd33aef8
parentf252494ff2ed28cf8bb83bf8b656492f8571e0f8 (diff)
downloadansible-081ce0e4e132a855550772379eedd7ae1be5335a.tar.gz
update ActionBase._low_level_execute_command to honor executable (#68315)
* update ActionBase._low_level_execute_command to honor executable * adding changelog fragment * renaming changelog fragment to .yml * noop change to bump shippable * adding raw_executable integration test * copying aliases from raw * removing blank lines * skipping aix and freebsd * noop to bump shippable * moving tests to raw/ * removing become_method: sudo ; it doesn't work on AIX * removing trailing blank line * forcing become_method: su to try to get AIX to work Co-authored-by: Rob Wagner <rob.wagner@sas.com> (cherry picked from commit 977b58740b7dbb328355c7c6970e1a6684101d13)
-rw-r--r--changelogs/fragments/68310-low_level_execute_command-honor-executable.yml2
-rw-r--r--lib/ansible/plugins/action/__init__.py4
-rwxr-xr-xtest/integration/targets/raw/runme.sh6
-rw-r--r--test/integration/targets/raw/runme.yml4
-rw-r--r--test/integration/targets/raw/tasks/main.yml24
5 files changed, 40 insertions, 0 deletions
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 0000000000..2cc5e6b0f7
--- /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 60da058d34..8bfaf202ee 100644
--- a/lib/ansible/plugins/action/__init__.py
+++ b/lib/ansible/plugins/action/__init__.py
@@ -1045,6 +1045,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 0000000000..079554277b
--- /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 0000000000..ea865bcafb
--- /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 715e4eb802..7f99eadf27 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"