Skip to content

Commit

Permalink
Split off ssm_document integration tests (rather than using it for al…
Browse files Browse the repository at this point in the history
…l test runs)
  • Loading branch information
tremble committed Jan 18, 2023
1 parent 6381aef commit d343232
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
time=20m

cloud/aws
connection_aws_ssm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- hosts: localhost
roles:
- role: ../setup_connection_aws_ssm
vars:
target_os: fedora
use_ssm_document: True
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- hosts: localhost
tasks:
- include_role:
name: ../setup_connection_aws_ssm
tasks_from: cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
- connection
- setup_connection_aws_ssm
31 changes: 31 additions & 0 deletions tests/integration/targets/connection_aws_ssm_ssm_document/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

PLAYBOOK_DIR=$(pwd)
set -eux

CMD_ARGS=("$@")

# Destroy Environment
cleanup() {

cd "${PLAYBOOK_DIR}"
ansible-playbook -c local aws_ssm_integration_test_teardown.yml "${CMD_ARGS[@]}"

}

trap "cleanup" EXIT

# Setup Environment
ansible-playbook -c local aws_ssm_integration_test_setup.yml "$@"

# Export the AWS Keys
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 \
"$@"
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
region: '{{ aws_region }}'
block:

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

- name: Check if instance_vars_to_delete.yml is present
stat:
path: "{{ playbook_dir }}/instance_vars_to_delete.yml"
Expand Down Expand Up @@ -75,11 +78,8 @@

- name: Delete SSM document
command: "aws ssm delete-document --name {{ ssm_document_name }}"
environment:
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}"
AWS_SESSION_TOKEN: "{{ security_token | default('') }}"
AWS_DEFAULT_REGION: "{{ aws_region }}"
environment: "{{ connection_env }}"
ignore_errors: yes

- name: Delete AWS keys environement
file:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- set_fact:
# As a lookup plugin we don't have access to module_defaults
connection_args:
region: "{{ aws_region }}"
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
aws_session_token: "{{ security_token | default(omit) }}"
connection_env:
AWS_DEFAULT_REGION: "{{ aws_region }}"
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}"
AWS_SESSION_TOKEN: "{{ security_token | default(omit) }}"
no_log: True
22 changes: 7 additions & 15 deletions tests/integration/targets/setup_connection_aws_ssm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
aws_caller_info:
register: aws_caller_info

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

- name: Ensure IAM instance role exists
iam_role:
name: "ansible-test-{{tiny_prefix}}-aws-ssm-role"
Expand Down Expand Up @@ -43,14 +46,6 @@
when:
- ami_configuration.ssm_parameter | default(False)
block:
- set_fact:
# As a lookup plugin we don't have access to module_defaults
connection_args:
region: "{{ aws_region }}"
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
aws_security_token: "{{ security_token | default(omit) }}"
no_log: True
- set_fact:
ssm_amis: "{{ lookup('aws_ssm', ami_configuration.ssm_parameter, **connection_args) }}"

Expand Down Expand Up @@ -101,13 +96,10 @@
when:
- encrypted_bucket | default(False)

- name: Create custom SSM document
command: "aws ssm create-document --content file://{{ role_path }}/files/ssm-document.json --name {{ ssm_document_name }} --document-type Session"
environment:
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}"
AWS_SESSION_TOKEN: "{{ security_token | default('') }}"
AWS_DEFAULT_REGION: "{{ aws_region }}"
- name: setup SSM document
include_tasks: 'ssm_document.yml'
when:
- use_ssm_document | default(False)

- name: Create S3 bucket
s3_bucket:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- block:
- name: Create custom SSM document
command: "aws ssm create-document --content file://{{ role_path }}/files/ssm-document.json --name {{ ssm_document_name }} --document-type Session"
environment: "{{ connection_env }}"
always:
- name: Create SSM vars_to_delete.yml
template:
dest: "{{ playbook_dir }}/ssm_vars_to_delete.yml"
src: ssm_vars_to_delete.yml.j2
ignore_errors: yes
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ ansible_aws_ssm_bucket_name={{ encrypted_s3_bucket_name }}
{% else %}
ansible_aws_ssm_bucket_name={{ s3_bucket_name }}
{% endif %}
{% if use_ssm_document | default(False) %}
ansible_aws_ssm_document={{ ssm_document_name }}
{% endif %}

# support tests that target testhost
[testhost:children]
Expand Down

0 comments on commit d343232

Please sign in to comment.