Skip to content

Commit

Permalink
Merge pull request #48 from abikouo/fix_integration_test_customized_ami
Browse files Browse the repository at this point in the history
Fix test_customized_ami - add missing RSA public and private ssh keys
  • Loading branch information
gravesm authored Jul 5, 2023
2 parents adca667 + 3542c85 commit 9349f65
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 5 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
env:
source: "./source"
aws_dir: "./amazon_aws"
crypto_dir: "./community.crypto"
ansible_version: "stable-2.14"
python_version: "3.9"
steps:
Expand All @@ -23,6 +24,7 @@ jobs:
install_python_dependencies: false
source_path: ${{ env.source }}

# checkout and install 'amazon.aws'
- name: checkout ansible-collections/amazon.aws
uses: ansible-network/github_actions/.github/actions/checkout_dependency@main
with:
Expand All @@ -36,6 +38,20 @@ jobs:
install_python_dependencies: true
source_path: ${{ env.amazon_aws }}

# checkout and install 'community.crypto'
- name: checkout ansible-collections/community.crypto
uses: ansible-network/github_actions/.github/actions/checkout_dependency@main
with:
repository: ansible-collections/community.crypto
path: ${{ env.crypto_dir }}
ref: main

- name: install community.crypto collection
uses: ansible-network/github_actions/.github/actions/build_install_collection@main
with:
install_python_dependencies: false
source_path: ${{ env.crypto_dir }}

- name: Create AWS/sts session credentials
uses: ansible-network/github_actions/.github/actions/ansible_aws_test_provider@main
with:
Expand All @@ -56,4 +72,4 @@ jobs:
collection_path: ${{ steps.install-collection.outputs.collection_path }}
python_version: ${{ env.python_version }}
ansible_version: ${{ env.ansible_version }}
ansible_test_requirement_files: ''
ansible_test_requirement_files: 'test-requirements.txt'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/tests/output/
/tests/integration/inventory
/changelogs/.plugin-cache.yaml
tests/integration/cloud-config-*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cryptography
6 changes: 6 additions & 0 deletions tests/integration/targets/setup_rsa_keys/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Delete temporary RSA key directory
ansible.builtin.file:
state: absent
path: "{{ setup_rsa_keys__tmpdir }}"
ignore_errors: true
16 changes: 16 additions & 0 deletions tests/integration/targets/setup_rsa_keys/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Create temporary directory to generate keys
ansible.builtin.tempfile:
state: directory
suffix: ssh
register: setup_rsa_keys__tmpdir
notify: 'Delete temporary RSA key directory'

- name: Generate RSA keys
community.crypto.openssh_keypair:
path: "{{ setup_rsa_keys__tmpdir.path }}/id_rsa"

- name: Define path to private and public keys
ansible.builtin.set_fact:
setup_rsa_keys__public_key_file: "{{ setup_rsa_keys__tmpdir.path }}/id_rsa.pub"
setup_rsa_keys__private_key_file: "{{ setup_rsa_keys__tmpdir.path }}/id_rsa"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ ami_vpc_name: "vpc-{{ resource_prefix }}"
ami_security_group: "security-group-{{ resource_prefix }}"
ami_security_group_desc: "Allow connection to instance via SSH port"
ami_key_name: "key-{{ resource_prefix }}"
ami_public_key_file: ~/.ssh/id_rsa.pub
ami_private_key_file: ~/.ssh/id_rsa.pub
ami_user_name: fedora
ami_ec2_instance_type: t2.micro
3 changes: 3 additions & 0 deletions tests/integration/targets/test_customized_ami/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- role: setup_rsa_keys
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
- name: Create key pair to connect to the VM
amazon.aws.ec2_key:
name: "{{ ami_key_name }}"
key_material: "{{ lookup('file', ami_public_key_file) }}"
key_material: "{{ lookup('file', setup_rsa_keys__public_key_file) }}"

- name: Get custom AMI information
amazon.aws.ec2_ami_info:
Expand Down Expand Up @@ -92,5 +92,5 @@
hostname: "{{ ami_ec2_instance_name }}"
ansible_ssh_user: "{{ ami_user_name }}"
ansible_host: "{{ test__ec2_instance.instances.0.public_ip_address }}"
ansible_ssh_common_args: -o "UserKnownHostsFile=/dev/null" -o StrictHostKeyChecking=no -i {{ ami_private_key_file }}
ansible_ssh_common_args: -o "UserKnownHostsFile=/dev/null" -o StrictHostKeyChecking=no -i {{ setup_rsa_keys__private_key_file }}
ansible_python_interpreter: auto
2 changes: 2 additions & 0 deletions tests/integration/targets/test_customized_ami/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- name: Test role 'customized_ami'
vars:
custom_ami_ec2_instance_type: t2.micro
custom_ami_public_key_file: "{{ setup_rsa_keys__public_key_file }}"
custom_ami_private_key_file: "{{ setup_rsa_keys__private_key_file }}"
block:
# Test: create custom AMI
- name: Create AMI with initial settings
Expand Down

0 comments on commit 9349f65

Please sign in to comment.