diff --git a/changelogs/fragments/85370-async-dir-variable-expansion-fix.yml b/changelogs/fragments/85370-async-dir-variable-expansion-fix.yml new file mode 100644 index 00000000000..7b3d68fcd5f --- /dev/null +++ b/changelogs/fragments/85370-async-dir-variable-expansion-fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - async_wrapper - fix variable expansion in async_dir to match remote_tmp behavior (https://github.com/ansible/ansible/issues/85370). diff --git a/lib/ansible/modules/async_wrapper.py b/lib/ansible/modules/async_wrapper.py index 65d013ca451..b9df4bddedb 100644 --- a/lib/ansible/modules/async_wrapper.py +++ b/lib/ansible/modules/async_wrapper.py @@ -241,7 +241,7 @@ def main(): async_dir = os.environ.get('ANSIBLE_ASYNC_DIR', '~/.ansible_async') # setup job output directory - jobdir = os.path.expanduser(async_dir) + jobdir = os.path.expanduser(os.path.expandvars(async_dir)) global job_path job_path = os.path.join(jobdir, jid) diff --git a/test/integration/targets/async/tasks/main.yml b/test/integration/targets/async/tasks/main.yml index bdce3dcba9f..443c1dafed2 100644 --- a/test/integration/targets/async/tasks/main.yml +++ b/test/integration/targets/async/tasks/main.yml @@ -279,7 +279,18 @@ - name: remove custom tmp dir after test file: path: '{{ custom_async_tmp }}' - state: absent + +- name: test async with $HOME variable expansion + command: echo "test" + async: 5 + poll: 1 + vars: + ansible_async_dir: "$HOME/.ansible_test_var_expansion" + +- name: verify $HOME was expanded and cleanup + file: + path: "{{ ansible_env.HOME }}/.ansible_test_var_expansion" + state: absent - name: Test that async has stdin command: >