diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2022-01-18 20:31:44 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-18 17:31:44 -0800 |
commit | a58c2a39d308a916c050bb67c1ff8c27913899ca (patch) | |
tree | 0cbb027d59f6beeba8d537b63255ec67a62a1379 | |
parent | 4eac144d7e7b8cdb5a167ae53e2e268ca2a94557 (diff) | |
download | ansible-a58c2a39d308a916c050bb67c1ff8c27913899ca.tar.gz |
include_vars initialize failed (#76754) (#76785)
* include_vars initialize failed
if source dir is given, but not present and traversal is empty you
can end up trying to access failed w/o it ever being defined.
also future proof for more corner cases in decision tree
(cherry picked from commit 89c884e2a2bd124b49bf9419f053f659a7d1c554)
-rw-r--r-- | changelogs/fragments/include_vars_failed.yml | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/action/include_vars.py | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/changelogs/fragments/include_vars_failed.yml b/changelogs/fragments/include_vars_failed.yml new file mode 100644 index 0000000000..8a3a5881f8 --- /dev/null +++ b/changelogs/fragments/include_vars_failed.yml @@ -0,0 +1,2 @@ +bugfixes: + - include_vars, properly initialize variable as there is corner case in which it can end up referenced and not defined diff --git a/lib/ansible/plugins/action/include_vars.py b/lib/ansible/plugins/action/include_vars.py index 07234537ac..7024002e5d 100644 --- a/lib/ansible/plugins/action/include_vars.py +++ b/lib/ansible/plugins/action/include_vars.py @@ -97,6 +97,7 @@ class ActionModule(ActionBase): self._set_args() results = dict() + failed = False if self.source_dir: self._set_dir_defaults() self._set_root_dir() @@ -164,13 +165,16 @@ class ActionModule(ActionBase): ) self.source_dir = path.join(current_dir, self.source_dir) + def _log_walk(self, error): + self._display.vvv('Issue with walking through "%s": %s' % (to_native(error.filename), to_native(error))) + def _traverse_dir_depth(self): """ Recursively iterate over a directory and sort the files in alphabetical order. Do not iterate pass the set depth. The default depth is unlimited. """ current_depth = 0 - sorted_walk = list(walk(self.source_dir)) + sorted_walk = list(walk(self.source_dir, onerror=self._log_walk)) sorted_walk.sort(key=lambda x: x[0]) for current_root, current_dir, current_files in sorted_walk: current_depth += 1 |