-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dmc5179/main
Updates to support migrating EC2 instances from RHEL 6 AMIs to RHEL 6 ELS AMI
- Loading branch information
Showing
9 changed files
with
276 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ vault.yml | |
artifacts/ | ||
__pycache__/ | ||
*~ | ||
.pytest_cache/ | ||
.pytest_cache/ | ||
ansible.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
--- | ||
# defaults file for rhel-6-els | ||
# defaults file for rhel-6-els | ||
|
||
instance_tag: 'rhel-6-els' | ||
#key_pair_name: '' | ||
#aws_region: | ||
aws_ssl_enabled: true | ||
#aws_ec2_url: 'https://ec2.{{ aws_region }}.amazonaws.com' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,5 +62,3 @@ | |
delegate_facts: true | ||
run_once: true | ||
register: tmp_private_key_md5 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
--- | ||
|
||
- name: Show donor instance info | ||
debug: | ||
var: donor_instance | ||
|
||
- name: Create replacement instance | ||
delegate_to: localhost | ||
community.aws.ec2_instance: | ||
aws_access_key: "{{ ansible_env.AWS_ACCESS_KEY_ID | default(omit) }}" | ||
aws_secret_key: "{{ ansible_env.AWS_SECRET_ACCESS_KEY | default(omit) }}" | ||
security_token: "{{ ansible_env.AWS_SESSION_TOKEN | default(omit) }}" | ||
#profile: "{{ inject.profile | default(omit) }}" | ||
region: "{{ ansible_env.AWS_DEFAULT_REGION | default(omit) }}" | ||
ec2_url: '{{ aws_ec2_url | default(omit) }}' | ||
validate_certs: '{{ aws_ssl_enabled }}' | ||
ebs_optimized: '{{ donor_instance.ebs_optimized }}' | ||
key_name: '{{ donor_instance.key_name }}' | ||
instance_type: '{{ donor_instance.instance_type }}' | ||
image_id: '{{ rhel_6_els_ami.image_id }}' | ||
wait: true | ||
name: "ELS replacement {{ donor_instance.instance_id }}" | ||
vpc_subnet_id: '{{ donor_instance.subnet_id }}' | ||
#group_id: '{{ donor_instance. }}' | ||
#instance_profile_name: '{{ donor_instance. }}' | ||
#instance_tags: '{{ donor_instance. }}' | ||
state: running | ||
register: replacement_instance | ||
|
||
- name: Wait for replace instance to finish booting | ||
wait_for: | ||
timeout: 60 | ||
delegate_to: localhost | ||
|
||
- name: Refetch replacement instance info | ||
delegate_to: localhost | ||
community.aws.ec2_instance_info: | ||
aws_access_key: "{{ ansible_env.AWS_ACCESS_KEY_ID | default(omit) }}" | ||
aws_secret_key: "{{ ansible_env.AWS_SECRET_ACCESS_KEY | default(omit) }}" | ||
security_token: "{{ ansible_env.AWS_SESSION_TOKEN | default(omit) }}" | ||
#profile: "{{ inject.profile | default(omit) }}" | ||
region: "{{ ansible_env.AWS_DEFAULT_REGION | default(omit) }}" | ||
ec2_url: '{{ aws_ec2_url | default(omit) }}' | ||
validate_certs: '{{ aws_ssl_enabled }}' | ||
instance_ids: | ||
- '{{ replacement_instance.instances[0].instance_id }}' | ||
register: replacement_instance | ||
|
||
- name: Show replacement instance info again | ||
debug: | ||
var: replacement_instance | ||
|
||
- name: Stop replacement instance | ||
delegate_to: localhost | ||
community.aws.ec2_instance: | ||
aws_access_key: "{{ ansible_env.AWS_ACCESS_KEY_ID | default(omit) }}" | ||
aws_secret_key: "{{ ansible_env.AWS_SECRET_ACCESS_KEY | default(omit) }}" | ||
security_token: "{{ ansible_env.AWS_SESSION_TOKEN | default(omit) }}" | ||
#profile: "{{ inject.profile | default(omit) }}" | ||
region: "{{ ansible_env.AWS_DEFAULT_REGION | default(omit) }}" | ||
ec2_url: '{{ aws_ec2_url | default(omit) }}' | ||
validate_certs: '{{ aws_ssl_enabled }}' | ||
state: stopped | ||
instance_ids: | ||
- '{{ replacement_instance.instances[0].instance_id }}' | ||
|
||
- name: Detach root volume from replacement instance | ||
delegate_to: localhost | ||
amazon.aws.ec2_vol: | ||
aws_access_key: "{{ ansible_env.AWS_ACCESS_KEY_ID | default(omit) }}" | ||
aws_secret_key: "{{ ansible_env.AWS_SECRET_ACCESS_KEY | default(omit) }}" | ||
security_token: "{{ ansible_env.AWS_SESSION_TOKEN | default(omit) }}" | ||
#profile: "{{ inject.profile | default(omit) }}" | ||
region: "{{ ansible_env.AWS_DEFAULT_REGION | default(omit) }}" | ||
ec2_url: '{{ aws_ec2_url | default(omit) }}' | ||
validate_certs: '{{ aws_ssl_enabled }}' | ||
id: '{{ replacement_instance.instances[0].block_device_mappings[0].ebs.volume_id }}' | ||
instance: None | ||
|
||
- name: Delete root volume from replacement instance | ||
delegate_to: localhost | ||
amazon.aws.ec2_vol: | ||
aws_access_key: "{{ ansible_env.AWS_ACCESS_KEY_ID | default(omit) }}" | ||
aws_secret_key: "{{ ansible_env.AWS_SECRET_ACCESS_KEY | default(omit) }}" | ||
security_token: "{{ ansible_env.AWS_SESSION_TOKEN | default(omit) }}" | ||
#profile: "{{ inject.profile | default(omit) }}" | ||
region: "{{ ansible_env.AWS_DEFAULT_REGION | default(omit) }}" | ||
ec2_url: '{{ aws_ec2_url | default(omit) }}' | ||
validate_certs: '{{ aws_ssl_enabled }}' | ||
id: '{{ replacement_instance.instances[0].block_device_mappings[0].ebs.volume_id }}' | ||
state: absent | ||
|
||
- name: Initialize my_snaps | ||
delegate_to: localhost | ||
set_fact: | ||
my_snaps: [] | ||
|
||
- name: Initialize my_vols | ||
delegate_to: localhost | ||
set_fact: | ||
my_vols: [] | ||
|
||
- name: Create snapshots of the donor instance volumes | ||
include_tasks: snapshot_one.yml | ||
vars: | ||
block_device: '{{ block_device_index }}' | ||
loop: '{{ donor_instance.block_device_mappings }}' | ||
loop_control: | ||
loop_var: block_device_index | ||
|
||
- name: Show my_snaps | ||
delegate_to: localhost | ||
debug: | ||
var: my_snaps | ||
|
||
- name: Start replacement instance | ||
delegate_to: localhost | ||
community.aws.ec2_instance: | ||
aws_access_key: "{{ ansible_env.AWS_ACCESS_KEY_ID | default(omit) }}" | ||
aws_secret_key: "{{ ansible_env.AWS_SECRET_ACCESS_KEY | default(omit) }}" | ||
security_token: "{{ ansible_env.AWS_SESSION_TOKEN | default(omit) }}" | ||
#profile: "{{ inject.profile | default(omit) }}" | ||
region: "{{ ansible_env.AWS_DEFAULT_REGION | default(omit) }}" | ||
ec2_url: '{{ aws_ec2_url | default(omit) }}' | ||
validate_certs: '{{ aws_ssl_enabled }}' | ||
state: running | ||
instance_ids: | ||
- '{{ replacement_instance.instances[0].instance_id }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
- name: Register the RHEL-6-ELS image ID | ||
amazon.aws.ec2_ami_info: | ||
aws_access_key: "{{ inject.aws_access_key | default(omit) }}" | ||
aws_secret_key: "{{ inject.aws_secret_key | default(omit) }}" | ||
profile: "{{ inject.profile | default(omit) }}" | ||
region: "{{ inject.region | default(omit) }}" | ||
aws_access_key: "{{ ansible_env.AWS_ACCESS_KEY_ID | default(omit) }}" | ||
aws_secret_key: "{{ ansible_env.AWS_SECRET_ACCESS_KEY | default(omit) }}" | ||
security_token: "{{ ansible_env.AWS_SESSION_TOKEN | default(omit) }}" | ||
#profile: "{{ inject.profile | default(omit) }}" | ||
region: "{{ ansible_env.AWS_DEFAULT_REGION | default(omit) }}" | ||
ec2_url: '{{ aws_ec2_url | default(omit) }}' | ||
validate_certs: '{{ aws_ssl_enabled }}' | ||
owners: 679593333241 | ||
filters: | ||
product-code: 65nbrx0tx3wb0wnchpwz5yvm | ||
product-code.type: marketplace | ||
name: RHEL-6.10ELS_HVM* | ||
delegate_to: 127.0.0.1 | ||
delegate_to: localhost | ||
register: rhel_6_els_amis | ||
|
||
- name: Identify the most recently published image | ||
delegate_to: localhost | ||
ansible.builtin.set_fact: | ||
rhel_6_els_ami: >- | ||
{{ rhel_6_els_amis.images | selectattr('name', 'defined') | sort(attribute='name') | last }} | ||
- name: Show RHEL 6 ELS AMI | ||
debug: | ||
var: rhel_6_els_ami | ||
|
||
# Build the instance and when you build the instance add it to an inventory group | ||
# that doesn't include the rhel6 instance. |
Oops, something went wrong.