ansible/test/integration/targets/copy/tasks/main.yml
Pilou ade593da52 Copy module: improve tests allowing to use a managed host which isn't the controller host (#25672)
* set output_dir_expanded using module result

'path' values are expanded using 'expandvars' too

* foo.txt is located in 'files' directory

* Use 'role_path' and 'connection: local' for local paths

'{{ role_path }}/tmp' is used for generated paths

* Use local connection with local paths

/tmp/ansible-test-abs-link and /tmp/ansible-test-abs-link-dir are
defined by targets/copy/files/subdir/subdir1/ansible-test-abs-link
and targets/copy/files/subdir/subdir1/ansible-test-abs-link-dir links.

* task names: add a suffix when same name is reused

* Check that item exists before checking file mode

then error message is more explicit when item doesn't exist

* Use output_dir_expanded only when necessary

* Enforce remote_user when root is required

* Fix remote path

* Use different local & remote user

this is useful when controller and managed hosts are identical

* Checks must not expect output of tested module to be right

* Use a temporary directory on the controller

* Use sha1 & md5 filters instead of hardcoded values

* Use 'remote_dir' for directory on managed host

* Workaround tempfile error on OS X

Error was:
temp_path = tempfile.mkdtemp(prefix='ansible_')
AttributeError: 'module' object has no attribute 'mkdtemp'"
2017-07-31 22:07:22 -07:00

53 lines
1.5 KiB
YAML

- block:
- name: Create a local temporary directory
shell: mktemp -d "${TMPDIR:-/tmp}/ansible_test.XXXXXXXXX"
register: tempfile_result
connection: local
- set_fact:
local_temp_dir: '{{ tempfile_result.stdout }}'
# output_dir is hardcoded in test/runner/lib/executor.py and created there
remote_dir: '{{ output_dir }}'
- name: create remote unprivileged remote user
user:
name: '{{ remote_unprivileged_user }}'
register: user
- file:
path: "{{ user.home }}/.ssh"
owner: '{{ remote_unprivileged_user }}'
state: directory
mode: 0700
- name: 'duplicate authorized_keys'
copy:
src: $HOME/.ssh/authorized_keys
dest: '{{ user.home }}/.ssh/authorized_keys'
owner: '{{ remote_unprivileged_user }}'
mode: 0600
remote_src: yes
- file:
path: "{{ remote_dir }}"
state: directory
remote_user: '{{ remote_unprivileged_user }}'
# execute tests tasks using an unprivileged user, this is useful to avoid
# local/remote ambiguity when controller and managed hosts are identical.
- import_tasks: tests.yml
remote_user: '{{ remote_unprivileged_user }}'
always:
- name: Cleaning
file:
path: '{{ local_temp_dir }}'
state: absent
connection: local
- name: remote unprivileged remote user
user:
name: '{{ remote_unprivileged_user }}'
state: absent
remove: yes