test_connection.yml (3491B)
1 # Adapted from Ansible's test/integration/targets/connection/test_connection.yml 2 3 - hosts: aoh 4 serial: 1 5 vars: 6 action_prefix: >- 7 {{ 'win_' if ansible_facts.os_family == 'Windows' else '' }} 8 local_tmp: /tmp/ansible-local 9 remote_tmp: >- 10 {{ 11 'C:/windows/temp/ansible-remote' 12 if ansible_facts.os_family == 'Windows' 13 else '/tmp/ansible-remote' 14 }} 15 16 tasks: 17 18 # SSH with scp has troubles with using complex filenames that require quoting 19 # or escaping. The more complex filename scenario is skipped in this mode. 20 # The default of sftp has no problems with these filenames. 21 - name: check if ssh with the scp file transfer is being tested 22 set_fact: 23 skip_complex_filename: >- 24 {{ 25 ansible_connection == "ssh" and 26 lookup("ansible.builtin.config", 27 "ssh_transfer_method", 28 plugin_name=ansible_connection, 29 plugin_type="connection", 30 ) == "scp" 31 }} 32 echo_string: 汉语 33 34 - name: set test filename 35 set_fact: 36 test_filename: 汉语-{{ skip_complex_filename | ternary("file", "['foo bar']") }}.txt 37 38 ### raw with unicode arg and output 39 40 - name: raw with unicode arg and output 41 raw: "{{ echo_commands[action_prefix ~ ansible_connection ~ '_' ~ (ansible_shell_type|default(''))] | default(echo_commands['default']) }}" 42 vars: 43 # Windows over AoH does not have a way to set the console codepage to allow UTF-8. We need to 44 # wrap the commands we send to the remote host to get it working. 45 echo_commands: 46 win_aoh_cmd: 'powershell.exe -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; echo {{ echo_string }}"' 47 default: echo {{ echo_string }} 48 register: command 49 - name: check output of raw with unicode arg and output 50 assert: 51 that: 52 - echo_string in command.stdout 53 - command is changed # as of 2.2, raw should default to changed: true for consistency w/ shell/command/script modules 54 55 ### copy local file with unicode filename and content 56 57 - name: create local file with unicode filename and content 58 local_action: lineinfile dest={{ local_tmp }}-汉语/{{ test_filename }} create=true line=汉语 59 - name: remove remote file with unicode filename and content 60 action: "{{ action_prefix }}file path={{ remote_tmp }}-汉语/{{ test_filename }} state=absent" 61 - name: create remote directory with unicode name 62 action: "{{ action_prefix }}file path={{ remote_tmp }}-汉语 state=directory" 63 - name: copy local file with unicode filename and content 64 action: "{{ action_prefix }}copy src={{ local_tmp }}-汉语/{{ test_filename }} dest={{ remote_tmp }}-汉语/{{ test_filename }}" 65 66 ### fetch remote file with unicode filename and content 67 68 - name: remove local file with unicode filename and content 69 local_action: file path={{ local_tmp }}-汉语/{{ test_filename }} state=absent 70 - name: fetch remote file with unicode filename and content 71 fetch: src={{ remote_tmp }}-汉语/{{ test_filename }} dest={{ local_tmp }}-汉语/{{ test_filename }} fail_on_missing=true validate_checksum=true flat=true 72 73 ### remove local and remote temp files 74 75 - name: remove local temp file 76 local_action: file path={{ local_tmp }}-汉语 state=absent 77 - name: remove remote temp file 78 action: "{{ action_prefix }}file path={{ remote_tmp }}-汉语 state=absent" 79 80 ### test wait_for_connection plugin 81 - wait_for_connection: