Skip to content

Commit

Permalink
testing playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Jan 8, 2024
1 parent 91f82fb commit 5dbd766
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 16 deletions.
12 changes: 1 addition & 11 deletions playbooks/webapp/tasks/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,6 @@
mode: 0400
when: rsa_key is changed

- name: Check if the vm exists
amazon.aws.ec2_instance_info:
filters:
instance-type: "{{ bastion_host_type }}"
key-name: "{{ deploy_flask_app_sshkey_pair_name }}"
vpc-id: "{{ vpc.vpc.id }}"
instance-state-name: running
register: vm_result

- name: Ensure IAM instance role exists
amazon.aws.iam_role:
name: "{{ ec2_iam_role_name }}"
Expand All @@ -237,7 +228,6 @@
register: role_output

- name: Create a virtual machine
when: vm_result.instances | length == 0
amazon.aws.ec2_instance:
name: "{{ deploy_flask_app_bastion_host_name }}"
instance_type: "{{ bastion_host_type }}"
Expand All @@ -254,7 +244,7 @@
- "{{ secgroup.group_id }}"
user_data: |
#!/bin/bash
yum install -y python3 python-virtualenv sshpass netcat
yum install -y python3 python-virtualenv sshpass netcat ansible
wait: true
state: started
register: vm_result
6 changes: 3 additions & 3 deletions playbooks/webapp/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resource_tags:
prefix: "{{ resource_prefix }}"
operation: create

image_filter: Fedora-Cloud-Base-35-*gp2-0
image_filter: Fedora-Cloud-Base-38-*
public_secgroup_name: "{{ resource_prefix }}-sg"
ec2_iam_role_name: "{{ resource_prefix }}-role"
rds_subnet_group_name: "{{ resource_prefix }}-rds-sg"
Expand All @@ -23,15 +23,15 @@ rds_instance_class: db.m6g.large
rds_instance_name: mysampledb123
rds_engine: postgres
rds_engine_version: "14.8"
bastion_host_type: t2.xlarge
bastion_host_type: t3.micro
bastion_host_venv_path: ~/env
rds_listening_port: 5432

# Variables for the deploy_flask_app role
deploy_flask_app_sshkey_pair_name: "{{ resource_prefix }}-key"
deploy_flask_app_bastion_host_name: "{{ resource_prefix }}-bastion"
deploy_flask_app_bastion_host_username: fedora
deploy_flask_app_workers_instance_type: t2.xlarge
deploy_flask_app_workers_instance_type: t3.micro
deploy_flask_app_workers_user_name: fedora
deploy_flask_app_number_of_workers: 2
deploy_flask_app_listening_port: 5000
Expand Down
4 changes: 4 additions & 0 deletions roles/deploy_flask_app/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@

- name: Start application container into workers
ansible.builtin.include_tasks: start_containers.yaml

- name: Display application URL
ansible.builtin.debug:
msg: "Application accessible at http://{{ deploy_flask_app_lb_result.elb.dns_name }}:{{ deploy_flask_app_listening_port }}"
4 changes: 2 additions & 2 deletions tests/integration/targets/setup_rsa_keys/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Delete temporary RSA key directory
- name: Delete RSA key directory
ansible.builtin.file:
state: absent
path: "{{ setup_rsa_keys__tmpdir }}"
path: "{{ setup_rsa_keys__path }}"
ignore_errors: true
1 change: 1 addition & 0 deletions tests/integration/targets/setup_rsa_keys/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ansible.builtin.file:
path: "{{ setup_rsa_keys__path }}"
state: directory
notify: 'Delete RSA key directory'

- name: Generate RSA keys
community.crypto.openssh_keypair:
Expand Down
1 change: 1 addition & 0 deletions tests/integration/targets/test_deploy_flask_app/aliases
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cloud/aws
role/deploy_flask_app
time=35m
unstable
2 changes: 2 additions & 0 deletions tests/integration/targets/test_playbook_webapp/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
time=35m
cloud/aws
12 changes: 12 additions & 0 deletions tests/integration/targets/test_playbook_webapp/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -eux

function cleanup() {
ansible-playbook webapp.yaml -e "operation=delete" "$@"
exit 1
}

trap 'cleanup "${@}"' ERR

ansible-playbook webapp.yaml "$@"
1 change: 1 addition & 0 deletions tests/integration/targets/test_playbook_webapp/webapp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- import_playbook: cloud.aws_ops.webapp.webapp

0 comments on commit 5dbd766

Please sign in to comment.