Keycloak
Ansible Role aws_ec2
Ansible role for creating, deleting, stopping and starting AWS EC2 instances for running keycloak tests.
Prerequisities
Role requires Ansible Collection
version
or higher.
Role assumes that user is authenticated to use AWS CLI, ie. that authentication
variables
and
are set in the environment.
Parameters
: AWS region for the resources to be created in.region
: Unique name of the instance cluster within the region. Defaults tocluster_name
.keycloak_{{ cluster_identifier }}
: Identifier to distingish multiple clusters within the region. Defaults tocluster_identifier
.${USER}
: Number of EC2 instances to be created.cluster_size
: Name of the AMI image to be used for spawning instances.ami_name
: AWS instance type.instance_type
: Size of instance storage device.instance_volume_size
: Path to Linux storage device.instance_device
For defaults see
.
Example Playbook
Example playbook
:
- hosts: localhost
connection: local
roles: [aws_ec2_client]
Create Instances
Using the example playbook run:
ansible-playbook aws_ec2.yml -e region=<REGION> -e operation=create
Replace with actual value, e.g.
.
Optionally you can override other parameters by
or
.
This operation will create the following 2 files:
- private SSH key.{{ cluster_name }}_{{ region }}.pem
- an Ansible host inventory file.{{ cluster_name }}_{{ region }}_inventory.yml
keycloak:
children:
"{{ cluster_name }}_{{ region }}":
vars:
ansible_user: ec2-user
ansible_become: yes
ansible_ssh_private_key_file: "{{ cluster_name }}_{{ region }}.pem"
hosts:
host-1-ip-address:
host-2-ip-address:
...
Notice that the created hosts will be included in Ansible group
and subgroup
.
Stop and Start instances
Using the example playbook run:
ansible-playbook aws_ec2.yml -e region=<REGION> -e operation=stop
After the instances are stopped their public IP addresses will be de-allocated.
ansible-playbook aws_ec2.yml -e region=<REGION> -e operation=start
After the instances are started again the role will re-create the host inventory file with updated public IP addresses.
Delete Instances
Using the example playbook run:
ansible-playbook aws_ec2.yml -e region=<REGION> -e operation=delete
This will remove created AWS resources and delete the host inventory file and private key.