2017-08-01 07:07:22 +02:00
|
|
|
- block:
|
|
|
|
|
|
|
|
- name: Create a local temporary directory
|
2018-01-16 06:15:04 +01:00
|
|
|
shell: mktemp -d /tmp/ansible_test.XXXXXXXXX
|
2017-08-01 07:07:22 +02:00
|
|
|
register: tempfile_result
|
2019-04-30 01:27:34 +02:00
|
|
|
delegate_to: localhost
|
2017-08-01 07:07:22 +02:00
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
local_temp_dir: '{{ tempfile_result.stdout }}'
|
|
|
|
remote_dir: '{{ output_dir }}'
|
2018-10-04 16:02:42 +02:00
|
|
|
symlinks:
|
|
|
|
ansible-test-abs-link: /tmp/ansible-test-abs-link
|
|
|
|
ansible-test-abs-link-dir: /tmp/ansible-test-abs-link-dir
|
|
|
|
circles: ../
|
|
|
|
invalid: invalid
|
|
|
|
invalid2: ../invalid
|
|
|
|
out_of_tree_circle: /tmp/ansible-test-link-dir/out_of_tree_circle
|
|
|
|
subdir3: ../subdir2/subdir3
|
2017-08-01 07:07:22 +02:00
|
|
|
|
2018-01-16 06:15:04 +01:00
|
|
|
- file: path={{local_temp_dir}} state=directory
|
|
|
|
name: ensure temp dir exists
|
|
|
|
|
2018-01-19 02:42:20 +01:00
|
|
|
# file cannot do this properly, use command instead
|
2018-10-04 16:02:42 +02:00
|
|
|
- name: Create symbolic link
|
|
|
|
command: "ln -s '{{ item.value }}' '{{ item.key }}'"
|
2018-01-19 02:42:20 +01:00
|
|
|
args:
|
|
|
|
chdir: '{{role_path}}/files/subdir/subdir1'
|
2018-10-04 16:02:42 +02:00
|
|
|
warn: no
|
|
|
|
with_dict: "{{ symlinks }}"
|
2018-01-19 02:42:20 +01:00
|
|
|
|
2017-08-15 18:41:16 +02:00
|
|
|
- name: Create remote unprivileged remote user
|
2017-08-01 07:07:22 +02:00
|
|
|
user:
|
|
|
|
name: '{{ remote_unprivileged_user }}'
|
|
|
|
register: user
|
|
|
|
|
2019-07-03 17:37:33 +02:00
|
|
|
- name: Check sudoers dir
|
|
|
|
stat:
|
|
|
|
path: /etc/sudoers.d
|
|
|
|
register: etc_sudoers
|
|
|
|
|
|
|
|
- name: Set sudoers.d path fact
|
|
|
|
set_fact:
|
|
|
|
sudoers_d_file: "{{ '/etc/sudoers.d' if etc_sudoers.stat.exists else '/usr/local/etc/sudoers.d' }}/{{ remote_unprivileged_user }}"
|
|
|
|
|
|
|
|
- name: Create sudoers file
|
|
|
|
copy:
|
|
|
|
dest: "{{ sudoers_d_file }}"
|
|
|
|
content: "{{ remote_unprivileged_user }} ALL=(ALL) NOPASSWD: ALL"
|
|
|
|
|
2017-08-01 07:07:22 +02:00
|
|
|
- file:
|
|
|
|
path: "{{ user.home }}/.ssh"
|
|
|
|
owner: '{{ remote_unprivileged_user }}'
|
|
|
|
state: directory
|
|
|
|
mode: 0700
|
|
|
|
|
2017-08-15 18:41:16 +02:00
|
|
|
- name: Duplicate authorized_keys
|
2017-08-01 07:07:22 +02:00
|
|
|
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 }}'
|
|
|
|
|
2019-04-03 18:37:59 +02:00
|
|
|
- import_tasks: acls.yml
|
|
|
|
when: ansible_system == 'Linux'
|
|
|
|
|
2020-04-17 23:09:32 +02:00
|
|
|
- import_tasks: check_mode.yml
|
|
|
|
|
2019-06-12 16:56:15 +02:00
|
|
|
# https://github.com/ansible/ansible/issues/57618
|
|
|
|
- name: Test diff contents
|
|
|
|
copy:
|
|
|
|
content: 'Ansible managed\n'
|
|
|
|
dest: "{{ local_temp_dir }}/file.txt"
|
|
|
|
diff: yes
|
|
|
|
register: diff_output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- 'diff_output.diff[0].before == ""'
|
|
|
|
- '"Ansible managed" in diff_output.diff[0].after'
|
|
|
|
|
2017-08-01 07:07:22 +02:00
|
|
|
always:
|
|
|
|
- name: Cleaning
|
|
|
|
file:
|
|
|
|
path: '{{ local_temp_dir }}'
|
|
|
|
state: absent
|
2019-04-30 01:27:34 +02:00
|
|
|
delegate_to: localhost
|
2017-08-01 07:07:22 +02:00
|
|
|
|
2018-10-04 16:02:42 +02:00
|
|
|
- name: Remove symbolic link
|
2018-01-19 02:42:20 +01:00
|
|
|
file:
|
2018-10-04 16:02:42 +02:00
|
|
|
path: '{{ role_path }}/files/subdir/subdir1/{{ item.key }}'
|
2018-01-19 02:42:20 +01:00
|
|
|
state: absent
|
2019-04-30 01:27:34 +02:00
|
|
|
delegate_to: localhost
|
2018-10-04 16:02:42 +02:00
|
|
|
with_dict: "{{ symlinks }}"
|
2018-01-19 02:42:20 +01:00
|
|
|
|
2017-08-15 18:41:16 +02:00
|
|
|
- name: Remote unprivileged remote user
|
2017-08-01 07:07:22 +02:00
|
|
|
user:
|
|
|
|
name: '{{ remote_unprivileged_user }}'
|
|
|
|
state: absent
|
|
|
|
remove: yes
|
2019-07-03 17:37:33 +02:00
|
|
|
|
|
|
|
- name: Remove sudoers.d file
|
|
|
|
file:
|
|
|
|
path: "{{ sudoers_d_file }}"
|
|
|
|
state: absent
|