diff options
author | Sam Doran <sdoran@redhat.com> | 2020-02-10 17:13:22 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-10 14:13:22 -0800 |
commit | a2b5af86dd67920ce350e2a6f292572a9f3762a4 (patch) | |
tree | 73d057a41f4f4204a9e412e163ea325b6e0d9a6e | |
parent | aaadf714380352d4fa3125127acaf10876c83f67 (diff) | |
download | ansible-a2b5af86dd67920ce350e2a6f292572a9f3762a4.tar.gz |
[stable-2.9] include_vars - fix stack trace when run ad-hoc with dirs parameter (#66581) (#66910)
Add integration test
There are a number of other parameters that result in stack traces as well when this module is used ad-hoc. I'm not sure if we're interested in fixing them all since this module isn't meant to be run ad-hoc.
(cherry picked from commit cc2376b782)
Co-authored-by: Sam Doran <sdoran@redhat.com>
5 files changed, 15 insertions, 4 deletions
diff --git a/changelogs/fragments/include_vars-ad-hoc-stack-trace-fix.yaml b/changelogs/fragments/include_vars-ad-hoc-stack-trace-fix.yaml new file mode 100644 index 0000000000..b77e2c1125 --- /dev/null +++ b/changelogs/fragments/include_vars-ad-hoc-stack-trace-fix.yaml @@ -0,0 +1,2 @@ +bugfixes: + - include_vars - fix stack trace when passing ``dirs`` in an ad-hoc command (https://github.com/ansible/ansible/issues/62633) diff --git a/lib/ansible/plugins/action/include_vars.py b/lib/ansible/plugins/action/include_vars.py index 25cf9dccdb..07234537ac 100644 --- a/lib/ansible/plugins/action/include_vars.py +++ b/lib/ansible/plugins/action/include_vars.py @@ -158,10 +158,11 @@ class ActionModule(ActionBase): ) self.source_dir = path_to_use else: - current_dir = ( - "/".join(self._task._ds._data_source.split('/')[:-1]) - ) - self.source_dir = path.join(current_dir, self.source_dir) + if hasattr(self._task._ds, '_data_source'): + current_dir = ( + "/".join(self._task._ds._data_source.split('/')[:-1]) + ) + self.source_dir = path.join(current_dir, self.source_dir) def _traverse_dir_depth(self): """ Recursively iterate over a directory and sort the files in diff --git a/test/integration/targets/include_vars-ad-hoc/aliases b/test/integration/targets/include_vars-ad-hoc/aliases new file mode 100644 index 0000000000..765b70da79 --- /dev/null +++ b/test/integration/targets/include_vars-ad-hoc/aliases @@ -0,0 +1 @@ +shippable/posix/group2 diff --git a/test/integration/targets/include_vars-ad-hoc/dir/inc.yml b/test/integration/targets/include_vars-ad-hoc/dir/inc.yml new file mode 100644 index 0000000000..c1d24c84a0 --- /dev/null +++ b/test/integration/targets/include_vars-ad-hoc/dir/inc.yml @@ -0,0 +1 @@ +porter: cable diff --git a/test/integration/targets/include_vars-ad-hoc/runme.sh b/test/integration/targets/include_vars-ad-hoc/runme.sh new file mode 100755 index 0000000000..51b68d2134 --- /dev/null +++ b/test/integration/targets/include_vars-ad-hoc/runme.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eux + +ansible testhost -i ../../inventory -m include_vars -a 'dir/inc.yml' "$@" +ansible testhost -i ../../inventory -m include_vars -a 'dir=dir' "$@" |