Skip to content

connection/aws_ssm - Fix integration tests on Windows managed nodes #2281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tests/integration/targets/connection_aws_ssm_*/instance_vars_to_delete.yml
tests/integration/targets/connection_aws_ssm_*/s3_vars_to_delete.yml
tests/integration/targets/connection_aws_ssm_*/ssm_inventory
tests/integration/targets/connection_aws_ssm_*/ssm_vars_to_delete.yml
tests/integration/targets/connection_aws_ssm_*/aws-env-vars.sh

### dotenv ###
.env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ time=12m
cloud/aws
connection_aws_ssm

unstable
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,5 @@ set +x
. ./aws-env-vars.sh
set -x

cd ../connection

# Execute Integration tests
INVENTORY="${PLAYBOOK_DIR}/ssm_inventory" ./test.sh \
-e target_hosts=aws_ssm \
"$@"
ansible-playbook ./test.yml -i "${PLAYBOOK_DIR}/ssm_inventory" "$@"
102 changes: 102 additions & 0 deletions tests/integration/targets/connection_aws_ssm_windows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
- name: Run connection/aws_ssm tests on Windows managed node.
hosts: aws_ssm_windows
gather_facts: false

vars:
local_dir: '{{ local_tmp }}-{{ inventory_hostname }}-汉语'
local_file: '{{ local_dir }}/汉语.txt'
remote_dir: '{{ remote_tmp }}-汉语'
remote_file: '{{ remote_dir }}/汉语.txt'
remote_empty_file: '{{ remote_dir }}/empty.txt'

tasks:
- name: Wait for connection
ansible.builtin.wait_for_connection:
timeout: 1000
sleep: 10

- name: Gather facts
ansible.builtin.setup:

### raw with unicode arg and output

- name: Raw with unicode arg and output
ansible.builtin.raw: echo 汉语
register: command

- name: Check output of raw with unicode arg and output
ansible.builtin.assert:
that:
- "'汉语' in command.stdout"
- command is changed # as of 2.2, raw should default to changed: true for consistency w/ shell/command/script modules

### copy local file with unicode filename and content

- name: Create local file with unicode filename and content
ansible.builtin.lineinfile:
dest: "{{ local_file }}"
create: true
line: 汉语
mode: "0755"
delegate_to: localhost

- name: Remove remote file with unicode filename and content
ansible.windows.win_file:
path: "{{ remote_file }}"
state: absent

- name: Create remote directory with unicode name
ansible.windows.win_file:
path: "{{ remote_dir }}"
state: directory

- name: Copy local file with unicode filename and content
ansible.windows.win_copy:
src: "{{ local_file }}"
dest: "{{ remote_file }}"

### fetch remote file with unicode filename and content

- name: Remove local file with unicode filename and content
ansible.builtin.file:
path: "{{ local_file }}"
state: absent
delegate_to: localhost

- name: Fetch remote file with unicode filename and content
ansible.builtin.fetch:
src: "{{ remote_file }}"
dest: "{{ local_file }}"
fail_on_missing: true
validate_checksum: true
flat: true

### remove local and remote temp files

- name: Remove local temp file
ansible.builtin.file:
path: "{{ local_file }}"
state: absent
delegate_to: localhost

- name: Remove remote temp file
ansible.windows.win_file:
path: "{{ remote_file }}"
state: absent

### copy an empty file
- name: Copy an empty file
ansible.windows.win_copy:
content: ''
dest: "{{ remote_empty_file }}"

- name: Stat empty file
ansible.windows.win_stat:
path: "{{ remote_empty_file }}"
register: stat_empty_file_cmd

- name: Check that empty file exists
ansible.builtin.assert:
that:
- stat_empty_file_cmd.stat.isreg # it is a regular file
- stat_empty_file_cmd.stat.size == 0
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
session_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region }}'
block:

- name: get ARN of calling user
amazon.aws.aws_caller_info:
register: aws_caller_info

- name: setup connection argments fact
ansible.builtin.include_tasks: 'connection_args.yml'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ aws_access_key_id = {{ session_access_key | default(aws_access_key) }}
aws_secret_access_key = {{ session_secret_key | default(aws_secret_key) }}
{% if security_token is defined or session_security_token is defined %}
aws_security_token = {{ session_security_token | default(security_token) }}
{% endif %}
{% endif %}
Loading