| 1 |
--- |
| 2 |
- name: Test connection and unicode file handling |
| 3 |
hosts: all |
| 4 |
gather_facts: false |
| 5 |
# Remove or suppress below if strategy: free is intentional for test |
| 6 |
# strategy: free |
| 7 |
|
| 8 |
vars: |
| 9 |
local_dir: "{{ local_tmp }}-{{ inventory_hostname }}-汉语" |
| 10 |
local_file: "{{ local_dir }}/汉语.txt" |
| 11 |
remote_dir: "{{ remote_tmp }}-汉语" |
| 12 |
remote_file: "{{ remote_dir }}/汉语.txt" |
| 13 |
remote_empty_file: "{{ remote_dir }}/empty.txt" |
| 14 |
|
| 15 |
tasks: |
| 16 |
- name: Wait for connection |
| 17 |
ansible.builtin.wait_for_connection: |
| 18 |
timeout: "{{ wait_for_timeout | default(100) }}" |
| 19 |
sleep: 10 |
| 20 |
|
| 21 |
- name: Gather facts |
| 22 |
ansible.builtin.setup: |
| 23 |
|
| 24 |
- name: Raw with unicode arg and output # noqa no-changed-when |
| 25 |
ansible.builtin.raw: echo 汉语 |
| 26 |
register: command |
| 27 |
|
| 28 |
- name: Check output of raw with unicode arg and output |
| 29 |
ansible.builtin.assert: |
| 30 |
that: |
| 31 |
- "'汉语' in command.stdout" |
| 32 |
- command is changed # as of 2.2, raw should default to changed: true for consistency w/ shell/command/script modules |
| 33 |
|
| 34 |
- name: Create local file with unicode filename and content |
| 35 |
ansible.builtin.lineinfile: |
| 36 |
path: "{{ local_file }}" |
| 37 |
create: true |
| 38 |
line: 汉语 |
| 39 |
mode: '0644' |
| 40 |
delegate_to: localhost |
| 41 |
|
| 42 |
- name: Remove remote file with unicode filename and content |
| 43 |
ansible.builtin.file: |
| 44 |
path: "{{ remote_file }}" |
| 45 |
state: absent |
| 46 |
|
| 47 |
- name: Create remote directory with unicode name |
| 48 |
ansible.builtin.file: |
| 49 |
path: "{{ remote_dir }}" |
| 50 |
state: directory |
| 51 |
mode: '0755' |
| 52 |
|
| 53 |
- name: Copy local file with unicode filename and content |
| 54 |
ansible.builtin.copy: |
| 55 |
src: "{{ local_file }}" |
| 56 |
dest: "{{ remote_file }}" |
| 57 |
mode: '0644' |
| 58 |
|
| 59 |
- name: Remove local file with unicode filename and content |
| 60 |
ansible.builtin.file: |
| 61 |
path: "{{ local_file }}" |
| 62 |
state: absent |
| 63 |
mode: '0644' |
| 64 |
delegate_to: localhost |
| 65 |
|
| 66 |
- name: Fetch remote file with unicode filename and content |
| 67 |
ansible.builtin.fetch: |
| 68 |
src: "{{ remote_file }}" |
| 69 |
dest: "{{ local_file }}" |
| 70 |
fail_on_missing: true |
| 71 |
validate_checksum: true |
| 72 |
flat: true |
| 73 |
|
| 74 |
- name: Remove local temp file |
| 75 |
ansible.builtin.file: |
| 76 |
path: "{{ local_file }}" |
| 77 |
state: absent |
| 78 |
mode: '0644' |
| 79 |
delegate_to: localhost |
| 80 |
|
| 81 |
- name: Remove remote temp file |
| 82 |
ansible.builtin.file: |
| 83 |
path: "{{ remote_file }}" |
| 84 |
state: absent |
| 85 |
|
| 86 |
- name: Test user manipulation |
| 87 |
when: "'aws_ssm_linux' in group_names" |
| 88 |
block: |
| 89 |
- name: Find ID when become=false # noqa no-changed-when |
| 90 |
ansible.builtin.command: id -u -n |
| 91 |
become: false |
| 92 |
register: id_cmd |
| 93 |
|
| 94 |
- name: Assert expected user |
| 95 |
ansible.builtin.assert: |
| 96 |
that: |
| 97 |
- id_cmd.stdout == 'ssm-user' |
| 98 |
|
| 99 |
- name: Include assume-user tests |
| 100 |
ansible.builtin.include_tasks: test_assume.yml |
| 101 |
loop: |
| 102 |
- ssm-agent |
| 103 |
- zuul |
| 104 |
- root |
| 105 |
loop_control: |
| 106 |
loop_var: user_name |
| 107 |
|
| 108 |
- name: Copy an empty file |
| 109 |
ansible.builtin.copy: |
| 110 |
content: "" |
| 111 |
dest: "{{ remote_empty_file }}" |
| 112 |
mode: '0644' |
| 113 |
|
| 114 |
# Can be used to manually test for a regression of |
| 115 |
# https://github.com/ansible-collections/amazon.aws/issues/2753 |
| 116 |
# but you need to increase the verbosity and inspect the logs... |
| 117 |
- name: Copy an empty file (Looping) |
| 118 |
ansible.builtin.copy: |
| 119 |
content: "" |
| 120 |
dest: "{{ remote_empty_file }}-{{ item }}" |
| 121 |
mode: '0644' |
| 122 |
loop: ["one", "two", "three"] |
| 123 |
|
| 124 |
- name: Stat empty file |
| 125 |
ansible.builtin.stat: |
| 126 |
path: "{{ remote_empty_file }}" |
| 127 |
register: stat_empty_file_cmd |
| 128 |
|
| 129 |
- name: Check that empty file exists |
| 130 |
ansible.builtin.assert: |
| 131 |
that: |
| 132 |
- stat_empty_file_cmd.stat.isreg # it is a regular file |
| 133 |
- stat_empty_file_cmd.stat.size == 0 |