1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#
# Ensure _make_tmp_path returns the same result across invocations for a single
# user account, and that the path returned cleans itself up on connection
# termination.
#
# Related bugs prior to the new-style handling:
# https://github.com/dw/mitogen/issues/239
# https://github.com/dw/mitogen/issues/301
- name: integration/action/make_tmp_path.yml
hosts: test-targets
tasks:
- include_tasks: ../_mitogen_only.yml
#
# non-root
#
- name: "Find regular temp path"
mitogen_action_script:
script: |
path = self._make_tmp_path()
self._remove_tmp_path(path)
register: tmp_path
- name: "Find regular temp path (new task)"
mitogen_action_script:
script: |
path = self._make_tmp_path()
self._remove_tmp_path(path)
register: tmp_path2
- name: "Find good temp path"
set_fact:
good_temp_path: "{{tmp_path.path|dirname}}"
- name: "Find good temp path (new task)"
set_fact:
good_temp_path2: "{{tmp_path2.path|dirname}}"
- name: "Verify common base path for both tasks"
assert:
that:
- good_temp_path == good_temp_path2
fail_msg: |
good_temp_path={{ good_temp_path }}
good_temp_path2={{ good_temp_path2 }}
- name: "Verify different subdir for both tasks"
assert:
that:
- tmp_path.path != tmp_path2.path
fail_msg: |
tmp_path={{ tmp_path }}
tmp_path2={{ tmp_path2 }}
#
# Verify subdirectory removal.
#
- name: Stat temp path
stat:
path: "{{tmp_path.path}}"
register: stat1
- name: Stat temp path (new task)
stat:
path: "{{tmp_path2.path}}"
register: stat2
- name: "Verify neither subdir exists any more"
assert:
that:
- not stat1.stat.exists
- not stat2.stat.exists
fail_msg: |
stat1={{ stat1 }}
stat2={{ stat2 }}
#
# Verify good directory persistence.
#
- name: Stat good temp path (new task)
stat:
path: "{{good_temp_path}}"
register: stat
- name: "Verify good temp path is persistent"
assert:
that:
- stat.stat.exists
fail_msg: |
stat={{ stat }}
#
# Write some junk into the temp path.
#
- name: "Write junk to temp path and verify it disappears"
custom_python_run_script:
script: |
from ansible.module_utils.basic import get_module_path
path = get_module_path() + '/foo.txt'
result['path'] = path
open(path, 'w').write("bar")
register: out
- name: "Verify junk disappeared."
stat:
path: "{{out.path}}"
register: out
- assert:
that:
- not out.stat.exists
fail_msg: |
out={{ out }}
#
# root
#
- name: "Find root temp path"
become: true
mitogen_action_script:
script: |
path = self._make_tmp_path()
self._remove_tmp_path(path)
register: tmp_path_root
- name: "Verify root temp path differs from regular path"
assert:
that:
- tmp_path2.path != tmp_path_root.path
- tmp_path2.path|dirname != tmp_path_root.path|dirname
fail_msg: |
tmp_path_root={{ tmp_path_root }}
tmp_path2={{ tmp_path2 }}
#
# readonly homedir
#
- name: Try writing to temp directory for the readonly_homedir user
become: true
become_user: mitogen__readonly_homedir
custom_python_run_script:
script: |
from ansible.module_utils.basic import get_module_path
path = get_module_path() + '/foo.txt'
result['path'] = path
open(path, 'w').write("bar")
register: tmp_path
when:
- become_unpriv_available
#
# modules get the same base dir
#
- name: "Verify modules get the same tmpdir as the action plugin"
custom_python_detect_environment:
register: out
- name: "Verify modules get the same tmpdir as the action plugin"
assert:
that:
- out.module_path.startswith(good_temp_path2)
- out.module_tmpdir.startswith(good_temp_path2)
fail_msg: |
out={{ out }}
tags:
- make_tmp_path
- mitogen_only
|