From ac9b84d2379a3c54d7bc18b571e6b69b9929506e Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 19 Aug 2018 19:23:40 +0100 Subject: [PATCH] issue #321: 2.4+ compatibility fixes, disable test on Vanilla. --- ansible_mitogen/mixins.py | 3 +- ansible_mitogen/runner.py | 3 ++ docs/ansible.rst | 38 +++++++++---------- docs/changelog.rst | 5 +-- .../integration/action/make_tmp_path.yml | 14 ++++++- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/ansible_mitogen/mixins.py b/ansible_mitogen/mixins.py index e0ca63b8..7d8f5518 100644 --- a/ansible_mitogen/mixins.py +++ b/ansible_mitogen/mixins.py @@ -315,7 +315,8 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase): # module_common and ensures no second temporary directory or atexit # handler is installed. self._connection._connect() - if not module_args.get('_ansible_tmpdir', object()): + + if ansible.__version__ > '2.5': module_args['_ansible_tmpdir'] = self._connection.get_temp_dir() return ansible_mitogen.planner.invoke( diff --git a/ansible_mitogen/runner.py b/ansible_mitogen/runner.py index 26cce71d..97a3cb36 100644 --- a/ansible_mitogen/runner.py +++ b/ansible_mitogen/runner.py @@ -66,6 +66,9 @@ except ImportError: # Prevent accidental import of an Ansible module from hanging on stdin read. import ansible.module_utils.basic ansible.module_utils.basic._ANSIBLE_ARGS = '{}' +ansible.module_utils.basic.get_module_path = lambda: ( + ansible_mitogen.target.temp_dir +) # For tasks that modify /etc/resolv.conf, non-Debian derivative glibcs cache # resolv.conf at startup and never implicitly reload it. Cope with that via an diff --git a/docs/ansible.rst b/docs/ansible.rst index 24b58b1d..556fd686 100644 --- a/docs/ansible.rst +++ b/docs/ansible.rst @@ -443,30 +443,30 @@ In summary, for each task Ansible may create one or more of: * ``$TMPDIR/ansible__payload_.../`` owned by the become user, * ``$TMPDIR/ansible-module-tmp-.../`` owned by the become user. -A directory must be created in order to maintain compatibility with Ansible, -as many modules introspect :data:`sys.argv` in order to find a directory where -they may write files, however for only one such directory exists for the -lifetime of each interpreter, its location is consistent for each target -account, and it is always privately owned by that account. - -The following candidate paths are tried until one is found that is writeable -and appears live on a filesystem that does not have ``noexec`` enabled: - -1. The ``$variable`` and tilde-expanded ``remote_tmp`` setting from - ``ansible.cfg``. -2. The ``$variable`` and tilde-expanded ``system_tmpdirs`` setting from - ``ansible.cfg``. -3. The ``TMPDIR`` environment variable. -4. The ``TEMP`` environment variable. -5. The ``TMP`` environment variable. +A directory must exist to maintain compatibility with Ansible, as many modules +introspect :data:`sys.argv` to find a directory where they may write files, +however only one directory exists for the lifetime of each interpreter, its +location is consistent for each target account, and it is always privately +owned by that account. + +The paths below are tried until one is found that is writeable and appears live +on a filesystem with ``noexec`` disabled: + +1. ``$variable`` and tilde-expanded ``remote_tmp`` setting from + ``ansible.cfg`` +2. ``$variable`` and tilde-expanded ``system_tmpdirs`` setting from + ``ansible.cfg`` +3. ``TMPDIR`` environment variable +4. ``TEMP`` environment variable +5. ``TMP`` environment variable 6. ``/tmp`` 7. ``/var/tmp`` 8. ``/usr/tmp`` -9. The current working directory. +9. Current working directory As the directory is created once at startup, and its content is managed by code -running remotely, no additional network roundtrips are required to create and -destroy it for each task requiring temporary storage. +running remotely, no additional network roundtrips are required to manage it +for each task requiring temporary storage. .. _ansible_process_env: diff --git a/docs/changelog.rst b/docs/changelog.rst index d4ac261c..d86b3358 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -47,9 +47,8 @@ Mitogen for Ansible * `#321 `_: temporary file handling has been simplified and additional network roundtrips have been removed, undoing earlier damage caused by compatibility bug fixes. A single directory - is created once at startup for each persistent interpreter, and the - ``remote_tmp`` setting is always ignored. See :ref:`ansible_tempfiles` for a - complete description. + is created once at startup for each persistent interpreter. See + :ref:`ansible_tempfiles` for a complete description. * `#324 `_: plays with a custom ``module_utils`` would fail due to fallout from the Python 3 port and related diff --git a/tests/ansible/integration/action/make_tmp_path.yml b/tests/ansible/integration/action/make_tmp_path.yml index 779280a3..eb39068b 100644 --- a/tests/ansible/integration/action/make_tmp_path.yml +++ b/tests/ansible/integration/action/make_tmp_path.yml @@ -11,6 +11,9 @@ hosts: test-targets any_errors_fatal: true tasks: + - meta: end_play + when: not is_mitogen + # # non-root # @@ -109,7 +112,16 @@ register: out # v2.6 related: https://github.com/ansible/ansible/pull/39833 - - name: "Verify modules get the same tmpdir as the action plugin" + - name: "Verify modules get the same tmpdir as the action plugin (<2.5)" + when: ansible_version.full < '2.5' + assert: + that: + - out.module_path == tmp_path.result + - out.module_tmpdir == None + + - name: "Verify modules get the same tmpdir as the action plugin (>2.5)" + when: ansible_version.full > '2.5' assert: that: + - out.module_path == tmp_path.result - out.module_tmpdir == tmp_path.result