From 135d5b1cf71f3949822c8d7b0a9d0203b7d645f1 Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Fri, 22 Nov 2024 14:04:01 -0500 Subject: [PATCH 01/15] Add experience for creating EC2 instance --- .../experiences/ec2_instance_create/README.md | 49 +++++++++++ .../experiences/ec2_instance_create/setup.yml | 35 ++++++++ .../template_surveys/create_ec2_instance.yml | 83 +++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 extensions/experiences/ec2_instance_create/README.md create mode 100644 extensions/experiences/ec2_instance_create/setup.yml create mode 100644 extensions/experiences/ec2_instance_create/template_surveys/create_ec2_instance.yml diff --git a/extensions/experiences/ec2_instance_create/README.md b/extensions/experiences/ec2_instance_create/README.md new file mode 100644 index 00000000..8566957a --- /dev/null +++ b/extensions/experiences/ec2_instance_create/README.md @@ -0,0 +1,49 @@ +# Create EC2 Instance Experience + +## Description + +This experience is designed to help get an EC2 instance up and running. + +## What This Experience Covers + +### Project Templates + +- **Create EC2 Instance Template**: Defined in `setup.yml`, this template helps organize and manage all necessary components for the ec2 creation experience. It ensures that relevant files, roles, and configurations are logically arranged, making it easier to maintain and execute automation tasks. + +### Job Templates + +- **Create EC2 Instance Job Template**: This template is designed to streamline the process of creating and EC2 instance. + +### Playbooks + +- **Playbooks**: + +### Surveys + +- **Create EC2 Instance Survey**: This survey provides an interactive way to specify parameters for creating the EC2 instance. + +## Resources Created by This Experience + +1. **Project Templates** + - Ensure that all relevant files, roles, and configurations are logically arranged, facilitating easier maintenance and execution of automation tasks. + +2. **Job Templates** + - Outline the necessary parameters and configurations to perform network backups using the provided playbooks. + +## How to Use + +1. **Use Seed Red Hat Experience Job** + - Ensure the custom EE is correctly built and available in your Ansible Automation Platform. Execute the "Seed Red Hat Experience" job within the Ansible Automation Platform, and select the "AWS Operations" category to load this experience. + +2. **Use the Job Templates** + - In the `Create EC2 Instance Automation Experience Project` execute the required job template to create the EC2 instance. Monitor the job execution and verify that the instance has been successfully created. + +## Contribution + +Contributions to this project are welcome. Please fork the repository, make your changes, and submit a pull request. + +## License + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text. This project is licensed under the MIT License. See the [LICENSE](https://github.com/redhat-cop/cloud.aws_ops/blob/main/LICENSE) file for details. diff --git a/extensions/experiences/ec2_instance_create/setup.yml b/extensions/experiences/ec2_instance_create/setup.yml new file mode 100644 index 00000000..cd97df5d --- /dev/null +++ b/extensions/experiences/ec2_instance_create/setup.yml @@ -0,0 +1,35 @@ +--- + +controller_labels: + - name: cloud.aws_ops + organization: "{{ organization | default('Default') }}" + - name: ec2_instance_experience + organization: "{{ organization | default('Default') }}" + - name: create_ec2_instance + organization: "{{ organization | default('Default') }}" + +controller_projects: + - name: AWS Operations / Create EC2 Instance + organization: "{{ organization | default('Default') }}" + scm_branch: main + scm_clean: no + scm_delete_on_update: no + scm_type: git + scp_update_on_launch: no + scm_url: https://github.com/redhat-cop/cloud.aws_ops.git + +controller_templates: + - name: AWS Operations / Create EC2 Instance + description: This job template creates an EC2 instance. + ask_inventory_on_launch: true + ask_execution_environment_on_launch: true + project: AWS Operations / Create EC2 Instance + playbook: extensions/experiences/ec2_instance_create/create_ec2_instance.yml + job_type: run + organization: "{{ organization | default('Default') }}" + labels: + - cloud.aws_ops + - ec2_instance_experience + - create_ec2_instance + survey_enabled: true + survey_spec: "{{ lookup('file', experience.path.replace('setup.yml', '') + 'template_surveys/create_ec2_instance.yml') | from_yaml }}" diff --git a/extensions/experiences/ec2_instance_create/template_surveys/create_ec2_instance.yml b/extensions/experiences/ec2_instance_create/template_surveys/create_ec2_instance.yml new file mode 100644 index 00000000..fb9e6ba3 --- /dev/null +++ b/extensions/experiences/ec2_instance_create/template_surveys/create_ec2_instance.yml @@ -0,0 +1,83 @@ +--- +name: Create EC2 Instance Survey +description: Survey to configure the EC2 creation experience +spec: + - type: text + question_name: AWS Region + question_description: Name of AWS region to create instance in + variable: ec2_instance_create_aws_region + required: true + + - type: text + question_name: Instance Name + question_description: Name of EC2 instance + variable: ec2_instance_create_instance_name: + required: true + + - type: text + question_name: Instance Type + question_description: Type of EC2 instance (e.g., t2.micro, m5.large) + variable: ec2_instance_create_instance_type + required: true + + - type: text + question_name: AMI ID + question_description: AMI ID for EC2 instance + variable: ec2_instance_create_ami_id + required: true + + - type: text + question_name: Key Pair Name + question_description: Name of key pair to use for SSH access to the EC2 instance + variable: ec2_instance_create_key_name + required: true + + - type: text + question_name: VPC Subnet ID + question_description: ID of subnet to launch EC2 instance in + variable: ec2_instance_create_vpc_subnet_id + required: true + + - type: multiplechoice + question_name: Create Elastic IP + question_description: Whether to create and associate an Elastic IP with the instance + variable: ec2_instance_create_associate_eip + choices: + - true + - false + required: false + default: false + + - type: multiplechoice + question_name: Create External Security Group + question_description: Whether to create and associate a security group for external access to the instance + variable: ec2_instance_create_associate_external_sg + choices: + - true + - false + required: false + default: false + + - type: text + question_name: External Security Group Name + question_description: Name of the security group for external access to the instance + variable: ec2_instance_create_external_sg_name + required: false + default: ec2_instance_create-default-external-sg + + - type: text + question_name: External Security Group Description + question_description: Description of the security group for external access to the instance + variable: ec2_instance_create_external_sg_description + required: false + default: Security group for external access + + - type: multiplechoice + question_name: Create Internet Gateway + question_description: Whether to create and attach an internet gateway + variable: ec2_instance_create_associate_igw + choices: + - true + - false + required: false + default: false From 91a362ee14805da7d838b401bb29048578a8451e Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Mon, 2 Dec 2024 08:49:30 -0500 Subject: [PATCH 02/15] Complete ec2 instance pattern --- extensions/patterns/ec2_instance/README.md | 53 +++++++ .../playbooks/create_ec2_instance.yml | 54 +++++++ .../ec2_instance/playbooks/group_vars/all.yml | 14 ++ .../playbooks/terminate_ec2_instance.yml | 12 ++ extensions/patterns/ec2_instance/setup.yml | 54 +++++++ .../template_surveys/create_ec2_instance.yml | 144 ++++++++++++++++++ .../terminate_ec2_instance.yml | 14 ++ 7 files changed, 345 insertions(+) create mode 100644 extensions/patterns/ec2_instance/README.md create mode 100644 extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml create mode 100644 extensions/patterns/ec2_instance/playbooks/group_vars/all.yml create mode 100644 extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml create mode 100644 extensions/patterns/ec2_instance/setup.yml create mode 100644 extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml create mode 100644 extensions/patterns/ec2_instance/template_surveys/terminate_ec2_instance.yml diff --git a/extensions/patterns/ec2_instance/README.md b/extensions/patterns/ec2_instance/README.md new file mode 100644 index 00000000..525bf5a2 --- /dev/null +++ b/extensions/patterns/ec2_instance/README.md @@ -0,0 +1,53 @@ +# Create EC2 Instance Pattern + +## Description + +This pattern is designed to help get an EC2 instance up and running. + +## What This Pattern Covers + +### Projects + +- **AWS Operations / EC2 Instance Patterns**: Defined in `setup.yml`, this project helps organize and manage all necessary components for the ec2 creation pattern. It ensures that relevant files, roles, and configurations are logically arranged, making it easier to maintain and execute automation tasks. + +### Job Templates + +- **AWS Operations / Create EC2 Instance**: This job template is designed to streamline the process of creating an EC2 instance. +- **AWS Operations / Terminate EC2 Instance**: This job template is designed to streamline the process of terminating (deleting) an EC2 instance. + +### Playbooks + +- **Create EC2 Instance Playbook**: This playbook creates an EC2 instance with optional configurations. +- **Terminate EC2 Instance Job Template**: This playbook terminates (deletes) an existing EC2 instance. + +### Surveys + +- **Create EC2 Instance Survey**: This survey provides an interactive way to specify parameters for creating the EC2 instance. +- **Terminate EC2 Instance Survey**: This survey provides an interactive way to specify parameters for terminating the EC2 instance. + +## Resources Created by This Pattern + +1. **Project** + - Ensures that all relevant files, roles, and configurations are logically arranged, facilitating easier maintenance and execution of automation tasks. + +2. **Job Templates** + - Outline the necessary parameters and configurations to perform network backups using the provided playbooks. + - Provide surveys for specifying parameters needed to run the job templates. + +## How to Use + +1. **Use Seed Red Hat Pattern Job** + - Ensure the custom EE is correctly built and available in your Ansible Automation Platform. Execute the "Seed Red Hat Pattern" job within the Ansible Automation Platform, and select the "AWS Operations" category to load this pattern. + +2. **Use the Job Templates** + - In the `AWS Operations / EC2 Instance Patterns` execute the required job template to create the EC2 instance. Monitor the job execution and verify that the instance has been successfully created. + +## Contribution + +Contributions to this project are welcome. Please fork the repository, make your changes, and submit a pull request. + +## License + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text. This project is licensed under the MIT License. See the [LICENSE](https://github.com/redhat-cop/cloud.aws_ops/blob/main/LICENSE) file for details. diff --git a/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml b/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml new file mode 100644 index 00000000..09af6765 --- /dev/null +++ b/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml @@ -0,0 +1,54 @@ +--- +- name: Create EC2 instance + hosts: localhost + gather_facts: false + module_defaults: + group/aws: + aws_region: "{{ aws_region }}" + tasks: + - name: Get AMIs for operating system and region + amazon.aws.ec2_ami_info: + filters: + architecture: x86_64 + name: "{{ os_type }}*" + owner: + - amazon + register: images + + - name: Set variables with dynamic values + ansible.builtin.set_fact: + image_id: "{{ (images.images | sort(attribute='name') | last).image_id }}" + key_name: "{{ key_name | default(instance_name ~ '-key') }}" + instance_tags: "{{ instance_tags | default('{}') | from_json }}" + eip_tags: "{{ eip_tags | default('{}') | from_json }}" + igw_tags: "{{ igw_tags | default('{}') | from_json }}" + sg_name: "{{ sg_name | default(instance_name ~ '-external-sg') }}" + sg_rule_names: "{{ sg_rules | map('split', ':') | map('first') | list }}" + sg_tags: "{{ sg_tags | default('{}') | from_json }}" + + - name: Translate sg rules + ansible.builtin.set_fact: + selected_sg_rules: "{{ sg_rule_names | map('extract', sg_rule_options) | list }}" + + - name: Run ec2_instance_create role + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_instance_create + vars: + ec2_instance_create_operation: create + ec2_instance_create_aws_region: "{{ aws_region }}" + ec2_instance_create_instance_name: "{{ instance_name }}" + ec2_instance_create_instance_type: "{{ instance_type }}" + ec2_instance_create_ami_id: "{{ image_id }}" + ec2_instance_create_key_name: "{{ key_name }}" + ec2_instance_create_vpc_id: "{{ vpc_id | default(omit) }}" + ec2_instance_create_vpc_subnet_id: "{{ subnet_id | default(omit) }}" + ec2_instance_create_tags: "{{ instance_tags | default(omit) }}" + ec2_instance_create_wait_for_boot: "{{ wait_for_boot | bool }}" + ec2_instance_create_associate_eip: "{{ associate_eip | bool }}" + ec2_instance_create_eip_tags: "{{ eip_tags | default(omit) }}" + ec2_instance_create_associate_igw: "{{ associate_igw | bool }}" + ec2_instance_create_igw_tags: "{{ igw_tags | default(omit) }}" + ec2_instance_create_associate_external_sg: "{{ associate_sg | bool }}" + ec2_instance_create_external_sg_name: "{{ sg_name }}" + ec2_instance_create_external_sg_description: "{{ sg_description }}" + ec2_instance_create_external_sg_rules: "{{ selected_sg_rules }}" diff --git a/extensions/patterns/ec2_instance/playbooks/group_vars/all.yml b/extensions/patterns/ec2_instance/playbooks/group_vars/all.yml new file mode 100644 index 00000000..ffb01bb9 --- /dev/null +++ b/extensions/patterns/ec2_instance/playbooks/group_vars/all.yml @@ -0,0 +1,14 @@ +--- +sg_rule_options: + http: + proto: tcp + ports: "80" + cidr_ip: 0.0.0.0/0 + https: + proto: tcp + ports: "443" + cidr_ip: 0.0.0.0/0 + ssh: + proto: tcp + ports: "22" + cidr_ip: "{{ sg_ssh_ip }}" diff --git a/extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml b/extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml new file mode 100644 index 00000000..2e242cbd --- /dev/null +++ b/extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml @@ -0,0 +1,12 @@ +--- +- name: Terminate EC2 instance + hosts: localhost + gather_facts: false + tasks: + - name: Run ec2_instance_create role + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_instance_create + vars: + ec2_instance_create_operation: delete + ec2_instance_create_aws_region: "{{ aws_region }}" + ec2_instance_create_instance_name: "{{ instance_name }}" diff --git a/extensions/patterns/ec2_instance/setup.yml b/extensions/patterns/ec2_instance/setup.yml new file mode 100644 index 00000000..9515ea67 --- /dev/null +++ b/extensions/patterns/ec2_instance/setup.yml @@ -0,0 +1,54 @@ +--- +controller_labels: + - name: cloud.aws_ops + organization: "{{ organization | default('Default') }}" + - name: ec2_instance_pattern + organization: "{{ organization | default('Default') }}" + - name: create_ec2_instance + organization: "{{ organization | default('Default') }}" + - name: terminate_ec2_instance + organization: "{{ organization | default('Default') }}" + +controller_projects: + - name: AWS Operations / EC2 Instance Patterns + organization: "{{ organization | default('Default') }}" + scm_branch: cloud-pattern-testing + scm_clean: no + scm_delete_on_update: no + scm_type: git + scp_update_on_launch: no + scm_url: https://github.com/hakbailey/cloud.aws_ops.git + +controller_templates: + - name: AWS Operations / Create EC2 Instance + description: This job template creates an EC2 instance. + ask_inventory_on_launch: true + ask_execution_environment_on_launch: true + ask_credential_on_launch: true + ask_verbosity_on_launch: true + project: AWS Operations / EC2 Instance Patterns + playbook: extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml + job_type: run + organization: "{{ organization }}" + labels: + - cloud.aws_ops + - ec2_instance_pattern + - create_ec2_instance + survey_enabled: true + survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/create_ec2_instance.yml') | from_yaml }}" + - name: AWS Operations / Terminate EC2 Instance + description: This job template terminates an EC2 instance. + ask_inventory_on_launch: true + ask_execution_environment_on_launch: true + ask_credential_on_launch: true + ask_verbosity_on_launch: true + project: AWS Operations / EC2 Instance Patterns + playbook: extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml + job_type: run + organization: "{{ organization }}" + labels: + - cloud.aws_ops + - ec2_instance_pattern + - terminate_ec2_instance + survey_enabled: true + survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/terminate_ec2_instance.yml') | from_yaml }}" diff --git a/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml b/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml new file mode 100644 index 00000000..20badcdd --- /dev/null +++ b/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml @@ -0,0 +1,144 @@ +--- +name: Create EC2 Instance Survey +description: Survey to configure the EC2 instance creation pattern +spec: + - type: text + question_name: AWS Region + question_description: Name of AWS region to create instance in + variable: aws_region + required: true + + - type: text + question_name: Instance Name + question_description: Name of EC2 instance + variable: instance_name + required: true + + - type: text + question_name: Instance Type + question_description: Type of EC2 instance (e.g., t2.micro, m5.large) + variable: instance_type + required: true + + - type: multiplechoice + question_name: Operating system image + question_description: Amazon Machine Image to use for the instance + variable: os_type + required: false + default: RHEL-9 + choices: + - RHEL-9 + - Windows_Server-2025-English-Full-Base + + - type: text + question_name: Key Pair Name + question_description: Name of key pair to use or create for SSH access to the EC2 instance, if not provided defaults to '{instance-name}-key' + variable: key_name + required: false + + - type: text + question_name: VPC ID + question_description: ID of VPC to launch EC2 instance and associated networking resources in, if not provided will launch in the default VPC for the region + variable: vpc_id + required: false + + - type: text + question_name: VPC Subnet ID + question_description: ID of subnet to launch EC2 instance in, if not provided will launch in the default zone of the VPC + variable: subnet_id + required: false + + - type: multiplechoice + question_name: Wait for Boot + question_description: Whether to wait for the EC2 instance to be in the running state before continuing, defaults to true + variable: wait_for_boot + required: false + default: "true" + choices: + - "true" + - "false" + + - type: text + question_name: Instance Tags + question_description: 'A dict of tags for the instance, e.g. {"environment: test", "owner": "team foobar"}' + variable: instance_tags + required: false + + - type: multiplechoice + question_name: Associate EIP + question_description: Whether to create and associate an Elastic IP (EIP) with the EC2 instance + variable: associate_eip + required: false + default: "false" + choices: + - "true" + - "false" + + - type: text + question_name: EIP Tags + question_description: 'A dict of tags for the EIP, e.g. {"environment: test", "owner": "team foobar"}' + variable: eip_tags + required: false + + - type: multiplechoice + question_name: Associate Internet Gateway + question_description: Whether to create and associate an internet gateway + variable: associate_igw + required: false + default: "false" + choices: + - "true" + - "false" + + - type: text + question_name: Internet Gateway Tags + question_description: 'A dict of tags for the internet gateway, e.g. {"environment: test", "owner": "team foobar"}' + variable: igw_tags + required: false + + - type: multiplechoice + question_name: Associate Security Group + question_description: Whether to create and associate a security group for external access + variable: associate_sg + required: false + default: "false" + choices: + - "true" + - "false" + + - type: text + question_name: Security Group Name + question_description: Name of the security group to create, defaults to '{instance_name}-external-sg' + variable: sg_name + required: false + + - type: text + question_name: Security Group description + question_description: Description for the security group, will only be used if a new security group is created + variable: sg_description + required: false + default: Security group for external access + + - type: multiselect + question_name: Security Group Rules + question_description: Rules for the security group + variable: sg_rules + required: false + default: 'ssh: Allow inbound SSH access from all IPv4 IP addresses (specify Security Group SSH Rule IP Range to limit to your network)' + choices: + - 'http: Allow inbound HTTP traffic from all IPv4 addresses' + - 'https: Allow inbound HTTPS access from all IPv4 addresses' + - 'ssh: Allow inbound SSH access from all IPv4 IP addresses (specify Security Group SSH Rule IP Range to limit to your network)' + + - type: text + question_name: Security Group SSH Rule IP Range + question_description: IPv4 address range from which to allow inbound SSH traffic + variable: sg_ssh_ip + required: false + default: 0.0.0.0/0 + + - type: text + question_name: Security Group Tags + question_description: 'A dict of tags for the security group, e.g. {"environment: test", "owner": "team foobar"}, will only be used if a new security group is created' + variable: sg_tags + required: false diff --git a/extensions/patterns/ec2_instance/template_surveys/terminate_ec2_instance.yml b/extensions/patterns/ec2_instance/template_surveys/terminate_ec2_instance.yml new file mode 100644 index 00000000..3c9f9adc --- /dev/null +++ b/extensions/patterns/ec2_instance/template_surveys/terminate_ec2_instance.yml @@ -0,0 +1,14 @@ +--- +name: Terminate EC2 Instance Survey +description: Survey to configure the EC2 instance termination pattern +spec: + - type: text + question_name: AWS Region + question_description: Name of AWS region to create instance in + variable: aws_region + required: true + - type: text + question_name: Instance Name + question_description: Name of EC2 instance + variable: ec2_instance_create_instance_name + required: true From 8e8ca35431dcd7bff854eac325bb30c0c45d145d Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Mon, 2 Dec 2024 09:20:33 -0500 Subject: [PATCH 03/15] Remove experiences folder --- .../experiences/ec2_instance_create/README.md | 49 ----------- .../experiences/ec2_instance_create/setup.yml | 35 -------- .../template_surveys/create_ec2_instance.yml | 83 ------------------- 3 files changed, 167 deletions(-) delete mode 100644 extensions/experiences/ec2_instance_create/README.md delete mode 100644 extensions/experiences/ec2_instance_create/setup.yml delete mode 100644 extensions/experiences/ec2_instance_create/template_surveys/create_ec2_instance.yml diff --git a/extensions/experiences/ec2_instance_create/README.md b/extensions/experiences/ec2_instance_create/README.md deleted file mode 100644 index 8566957a..00000000 --- a/extensions/experiences/ec2_instance_create/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# Create EC2 Instance Experience - -## Description - -This experience is designed to help get an EC2 instance up and running. - -## What This Experience Covers - -### Project Templates - -- **Create EC2 Instance Template**: Defined in `setup.yml`, this template helps organize and manage all necessary components for the ec2 creation experience. It ensures that relevant files, roles, and configurations are logically arranged, making it easier to maintain and execute automation tasks. - -### Job Templates - -- **Create EC2 Instance Job Template**: This template is designed to streamline the process of creating and EC2 instance. - -### Playbooks - -- **Playbooks**: - -### Surveys - -- **Create EC2 Instance Survey**: This survey provides an interactive way to specify parameters for creating the EC2 instance. - -## Resources Created by This Experience - -1. **Project Templates** - - Ensure that all relevant files, roles, and configurations are logically arranged, facilitating easier maintenance and execution of automation tasks. - -2. **Job Templates** - - Outline the necessary parameters and configurations to perform network backups using the provided playbooks. - -## How to Use - -1. **Use Seed Red Hat Experience Job** - - Ensure the custom EE is correctly built and available in your Ansible Automation Platform. Execute the "Seed Red Hat Experience" job within the Ansible Automation Platform, and select the "AWS Operations" category to load this experience. - -2. **Use the Job Templates** - - In the `Create EC2 Instance Automation Experience Project` execute the required job template to create the EC2 instance. Monitor the job execution and verify that the instance has been successfully created. - -## Contribution - -Contributions to this project are welcome. Please fork the repository, make your changes, and submit a pull request. - -## License - -GNU General Public License v3.0 or later. - -See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text. This project is licensed under the MIT License. See the [LICENSE](https://github.com/redhat-cop/cloud.aws_ops/blob/main/LICENSE) file for details. diff --git a/extensions/experiences/ec2_instance_create/setup.yml b/extensions/experiences/ec2_instance_create/setup.yml deleted file mode 100644 index cd97df5d..00000000 --- a/extensions/experiences/ec2_instance_create/setup.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- - -controller_labels: - - name: cloud.aws_ops - organization: "{{ organization | default('Default') }}" - - name: ec2_instance_experience - organization: "{{ organization | default('Default') }}" - - name: create_ec2_instance - organization: "{{ organization | default('Default') }}" - -controller_projects: - - name: AWS Operations / Create EC2 Instance - organization: "{{ organization | default('Default') }}" - scm_branch: main - scm_clean: no - scm_delete_on_update: no - scm_type: git - scp_update_on_launch: no - scm_url: https://github.com/redhat-cop/cloud.aws_ops.git - -controller_templates: - - name: AWS Operations / Create EC2 Instance - description: This job template creates an EC2 instance. - ask_inventory_on_launch: true - ask_execution_environment_on_launch: true - project: AWS Operations / Create EC2 Instance - playbook: extensions/experiences/ec2_instance_create/create_ec2_instance.yml - job_type: run - organization: "{{ organization | default('Default') }}" - labels: - - cloud.aws_ops - - ec2_instance_experience - - create_ec2_instance - survey_enabled: true - survey_spec: "{{ lookup('file', experience.path.replace('setup.yml', '') + 'template_surveys/create_ec2_instance.yml') | from_yaml }}" diff --git a/extensions/experiences/ec2_instance_create/template_surveys/create_ec2_instance.yml b/extensions/experiences/ec2_instance_create/template_surveys/create_ec2_instance.yml deleted file mode 100644 index fb9e6ba3..00000000 --- a/extensions/experiences/ec2_instance_create/template_surveys/create_ec2_instance.yml +++ /dev/null @@ -1,83 +0,0 @@ ---- -name: Create EC2 Instance Survey -description: Survey to configure the EC2 creation experience -spec: - - type: text - question_name: AWS Region - question_description: Name of AWS region to create instance in - variable: ec2_instance_create_aws_region - required: true - - - type: text - question_name: Instance Name - question_description: Name of EC2 instance - variable: ec2_instance_create_instance_name: - required: true - - - type: text - question_name: Instance Type - question_description: Type of EC2 instance (e.g., t2.micro, m5.large) - variable: ec2_instance_create_instance_type - required: true - - - type: text - question_name: AMI ID - question_description: AMI ID for EC2 instance - variable: ec2_instance_create_ami_id - required: true - - - type: text - question_name: Key Pair Name - question_description: Name of key pair to use for SSH access to the EC2 instance - variable: ec2_instance_create_key_name - required: true - - - type: text - question_name: VPC Subnet ID - question_description: ID of subnet to launch EC2 instance in - variable: ec2_instance_create_vpc_subnet_id - required: true - - - type: multiplechoice - question_name: Create Elastic IP - question_description: Whether to create and associate an Elastic IP with the instance - variable: ec2_instance_create_associate_eip - choices: - - true - - false - required: false - default: false - - - type: multiplechoice - question_name: Create External Security Group - question_description: Whether to create and associate a security group for external access to the instance - variable: ec2_instance_create_associate_external_sg - choices: - - true - - false - required: false - default: false - - - type: text - question_name: External Security Group Name - question_description: Name of the security group for external access to the instance - variable: ec2_instance_create_external_sg_name - required: false - default: ec2_instance_create-default-external-sg - - - type: text - question_name: External Security Group Description - question_description: Description of the security group for external access to the instance - variable: ec2_instance_create_external_sg_description - required: false - default: Security group for external access - - - type: multiplechoice - question_name: Create Internet Gateway - question_description: Whether to create and attach an internet gateway - variable: ec2_instance_create_associate_igw - choices: - - true - - false - required: false - default: false From 6fb611dd42f8bc00c70393ee0d0425d1b50e2ec0 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Mon, 2 Dec 2024 16:57:50 -0500 Subject: [PATCH 04/15] Require IP range for inbound SSH traffic --- .../patterns/ec2_instance/playbooks/create_ec2_instance.yml | 6 ++++++ .../ec2_instance/template_surveys/create_ec2_instance.yml | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml b/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml index 09af6765..cb4611ec 100644 --- a/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml +++ b/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml @@ -26,6 +26,12 @@ sg_rule_names: "{{ sg_rules | map('split', ':') | map('first') | list }}" sg_tags: "{{ sg_tags | default('{}') | from_json }}" + - name: Check whether IP range is specified for SSH access + ansible.builtin.fail: + msg: "Must specify Security Group SSH Rule IP Range when allowing inbound SSH traffic." + when: + '"ssh" in sg_rule_names and sg_ssh_ip | default("", true) == ""' + - name: Translate sg rules ansible.builtin.set_fact: selected_sg_rules: "{{ sg_rule_names | map('extract', sg_rule_options) | list }}" diff --git a/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml b/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml index 20badcdd..21e07577 100644 --- a/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml +++ b/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml @@ -124,18 +124,16 @@ spec: question_description: Rules for the security group variable: sg_rules required: false - default: 'ssh: Allow inbound SSH access from all IPv4 IP addresses (specify Security Group SSH Rule IP Range to limit to your network)' choices: - 'http: Allow inbound HTTP traffic from all IPv4 addresses' - 'https: Allow inbound HTTPS access from all IPv4 addresses' - - 'ssh: Allow inbound SSH access from all IPv4 IP addresses (specify Security Group SSH Rule IP Range to limit to your network)' + - 'ssh: Allow inbound SSH access from an IPv4 IP address range (must specify Security Group SSH Rule IP Range)' - type: text question_name: Security Group SSH Rule IP Range question_description: IPv4 address range from which to allow inbound SSH traffic variable: sg_ssh_ip required: false - default: 0.0.0.0/0 - type: text question_name: Security Group Tags From 676c366b90f6fe3c728a6a519c3f2b027ced46f5 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Mon, 2 Dec 2024 17:36:35 -0500 Subject: [PATCH 05/15] Add execution environment definition --- .../exec_env/execution-environment.yml | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 extensions/patterns/ec2_instance/exec_env/execution-environment.yml diff --git a/extensions/patterns/ec2_instance/exec_env/execution-environment.yml b/extensions/patterns/ec2_instance/exec_env/execution-environment.yml new file mode 100644 index 00000000..f7bceb39 --- /dev/null +++ b/extensions/patterns/ec2_instance/exec_env/execution-environment.yml @@ -0,0 +1,29 @@ +--- +version: 3 + +dependencies: + ansible_core: + package_pip: ansible-core + ansible_runner: + package_pip: ansible-runner + galaxy: + collections: + - name: cloud.aws_ops + source: https://github.com/hakbailey/cloud.aws_ops.git + type: git + version: cloud-pattern-testing + - name: amazon.aws + source: https://github.com/ansible-collections/amazon.aws.git + type: git + version: main + python: + - boto3 + - botocore + +images: + base_image: + name: docker.io/redhat/ubi9:latest + +additional_build_steps: + append_base: | + RUN yum install -y git From 58bae451f568af6707ee0cabbf7379a2ee4d5459 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Wed, 4 Dec 2024 12:53:47 -0500 Subject: [PATCH 06/15] Added template_rhdh folder --- extensions/patterns/ec2_instance/template_rhdh/ec2_instance.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 extensions/patterns/ec2_instance/template_rhdh/ec2_instance.yaml diff --git a/extensions/patterns/ec2_instance/template_rhdh/ec2_instance.yaml b/extensions/patterns/ec2_instance/template_rhdh/ec2_instance.yaml new file mode 100644 index 00000000..e69de29b From ad328e6a11b443597973ff797a1fa91956926f13 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Thu, 5 Dec 2024 20:32:37 -0500 Subject: [PATCH 07/15] Updates to configure_ec2 pattern --- extensions/patterns/configure_ec2/README.md | 53 ++++++++++ .../exec_env/execution-environment.yml | 29 ++++++ .../playbooks/create_ec2_instance.yml | 58 +++++++++++ .../playbooks/group_vars/all.yml | 20 ++++ .../playbooks/terminate_ec2_instance.yml | 24 +++++ extensions/patterns/configure_ec2/setup.yml | 61 ++++++++++++ .../template_surveys/create_ec2_instance.yml | 97 +++++++++++++++++++ .../terminate_ec2_instance.yml | 21 ++++ 8 files changed, 363 insertions(+) create mode 100644 extensions/patterns/configure_ec2/README.md create mode 100644 extensions/patterns/configure_ec2/exec_env/execution-environment.yml create mode 100644 extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml create mode 100644 extensions/patterns/configure_ec2/playbooks/group_vars/all.yml create mode 100644 extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml create mode 100644 extensions/patterns/configure_ec2/setup.yml create mode 100644 extensions/patterns/configure_ec2/template_surveys/create_ec2_instance.yml create mode 100644 extensions/patterns/configure_ec2/template_surveys/terminate_ec2_instance.yml diff --git a/extensions/patterns/configure_ec2/README.md b/extensions/patterns/configure_ec2/README.md new file mode 100644 index 00000000..14647d01 --- /dev/null +++ b/extensions/patterns/configure_ec2/README.md @@ -0,0 +1,53 @@ +# Configure EC2 Instance Pattern + +## Description + +This pattern is designed to help get an EC2 instance up and running. + +## What This Pattern Covers + +### Projects + +- **AWS Operations / Configure EC2 Instance Pattern Project**: Defined in `setup.yml`, this project helps organize and manage all necessary components for the Configure EC2 Instance pattern. It ensures that relevant files, roles, and configurations are logically arranged, making it easier to maintain and execute automation tasks. + +### Job Templates + +- **AWS Operations / Create EC2 Instance**: This job template is designed to streamline the process of creating an EC2 instance. +- **AWS Operations / Terminate EC2 Instance**: This job template is designed to streamline the process of terminating (deleting) an EC2 instance. + +### Playbooks + +- **Create EC2 Instance Playbook**: This playbook creates an EC2 instance with optional networking configurations. +- **Terminate EC2 Instance Playbook**: This playbook terminates (deletes) an existing EC2 instance and associated networking resources. + +### Surveys + +- **Create EC2 Instance Survey**: This survey provides an interactive way to specify parameters for creating the EC2 instance. +- **Terminate EC2 Instance Survey**: This survey provides an interactive way to specify parameters for terminating the EC2 instance. + +## Resources Created by This Pattern + +1. **Project** + - Ensures that all relevant files, roles, and configurations are logically arranged, facilitating easier maintenance and execution of automation tasks. + +2. **Job Templates** + - Outline the necessary parameters and configurations to perform network backups using the provided playbooks. + - Provide surveys for specifying parameters needed to run the job templates. + +## How to Use + +1. **Use Seed Red Hat Pattern Job** + - Ensure the custom EE is correctly built and available in your Ansible Automation Platform. Execute the "Seed Red Hat Pattern" job within the Ansible Automation Platform, and select the "AWS Operations" category to load this pattern. + +2. **Use the Job Templates** + - In the `AWS Operations / EC2 Instance Patterns` execute the required job template to create the EC2 instance. Monitor the job execution and verify that the instance has been successfully created. + +## Contribution + +Contributions to this project are welcome. Please fork the repository, make your changes, and submit a pull request. + +## License + +GNU General Public License v3.0 or later. + +See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text. This project is licensed under the MIT License. See the [LICENSE](https://github.com/redhat-cop/cloud.aws_ops/blob/main/LICENSE) file for details. diff --git a/extensions/patterns/configure_ec2/exec_env/execution-environment.yml b/extensions/patterns/configure_ec2/exec_env/execution-environment.yml new file mode 100644 index 00000000..f7bceb39 --- /dev/null +++ b/extensions/patterns/configure_ec2/exec_env/execution-environment.yml @@ -0,0 +1,29 @@ +--- +version: 3 + +dependencies: + ansible_core: + package_pip: ansible-core + ansible_runner: + package_pip: ansible-runner + galaxy: + collections: + - name: cloud.aws_ops + source: https://github.com/hakbailey/cloud.aws_ops.git + type: git + version: cloud-pattern-testing + - name: amazon.aws + source: https://github.com/ansible-collections/amazon.aws.git + type: git + version: main + python: + - boto3 + - botocore + +images: + base_image: + name: docker.io/redhat/ubi9:latest + +additional_build_steps: + append_base: | + RUN yum install -y git diff --git a/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml b/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml new file mode 100644 index 00000000..25b10b21 --- /dev/null +++ b/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml @@ -0,0 +1,58 @@ +--- +- name: Create EC2 instance + hosts: localhost + gather_facts: false + module_defaults: + group/aws: + aws_region: "{{ aws_region }}" + tasks: + - name: Get security group rules list from string input + ansible.builtin.set_fact: + sg_rules_list: "{{ sg_rules | from_yaml }}" + + - name: Add external access rules to security group rules if needed + ansible.builtin.set_fact: + final_sg_rules: "{{ create_external_access_resources | ternary(sg_rules_list + allow_external_access_sg_rules, sg_rules_list) }}" + + - name: Get RHEL 9 AMI ID if needed + when: ami_id | default("", true) == "" + block: + - name: Get RHEL-9 images + amazon.aws.ec2_ami_info: + filters: + architecture: x86_64 + name: "RHEL-9*" + owner: + - amazon + register: images + - name: Update ami_id variable + ansible.builtin.set_fact: + ami_id: "{{ (images.images | sort(attribute='name') | last).image_id }}" + + - name: Create networking resources + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_networking_resources + vars: + ec2_networking_resources_operation: create + ec2_networking_resources_vpc_name: "{{ vpc_name }}" + ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" + ec2_networking_resources_subnet_cidr_block: "{{ subnet_cidr }}" + ec2_networking_resources_sg_name: "{{ sg_name }}" + ec2_networking_resources_sg_description: "{{ sg_description }}" + ec2_networking_resources_sg_rules: "{{ final_sg_rules }}" + ec2_networking_resources_create_igw: "{{ create_external_access_resources }}" + + - name: Create EC2 instance + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_instance_create_delete + vars: + ec2_instance_create_delete_operation: create + ec2_instance_create_delete_instance_name: "{{ instance_name }}" + ec2_instance_create_delete_instance_type: "{{ instance_type }}" + ec2_instance_create_delete_ami_id: "{{ ami_id }}" + ec2_instance_create_delete_key_name: "{{ key_name }}" + ec2_instance_create_delete_vpc_subnet_id: "{{ ec2_networking_resources_subnet_result.subnet.id }}" + ec2_instance_create_delete_wait_for_state: "{{ wait_for_state | bool }}" + ec2_instance_create_delete_associate_security_groups: "{{ [ sg_name ] }}" + ec2_instance_create_delete_associate_eip: "{{ create_external_access_resources }}" + ec2_instance_create_delete_instance_tags: "{{ instance_tags | default('{}', true) | from_json }}" diff --git a/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml b/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml new file mode 100644 index 00000000..aacd5d9c --- /dev/null +++ b/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml @@ -0,0 +1,20 @@ +key_name: "{{ instance_name }}-key" +wait_for_state: true +vpc_name: "{{instance_name}}-vpc" +vpc_cidr: 10.0.0.0/24 +subnet_cidr: 10.0.0.0/25 +sg_name: "{{ instance_name }}-sg" +sg_description: "Security group for EC2 instance {{ instance_name }}" +sg_rules: + - proto: tcp + ports: 22 + cidr_ip: "{{ vpc_cidr }}" +external_access: true +create_external_access_resources: "{{ external_access | bool }}" +allow_external_access_sg_rules: + - proto: tcp + ports: 80 + cidr_ip: 0.0.0.0/0 + - ports: tcp + ports: 443 + cidr_ip: 0.0.0.0/0 diff --git a/extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml b/extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml new file mode 100644 index 00000000..a8668b5a --- /dev/null +++ b/extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml @@ -0,0 +1,24 @@ +--- +- name: Terminate EC2 instance + hosts: localhost + gather_facts: false + module_defaults: + group/aws: + aws_region: "{{ aws_region }}" + tasks: + - name: Set ec2_instance_create_delete role vars + ansible.builtin.set_fact: + ec2_instance_create_delete_operation: delete + ec2_instance_create_delete_instance_name: "{{ instance_name }}" + ec2_instance_create_delete_key_name: "{{ key_name | default(omit, true) }}" + + - name: Delete EC2 instance + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_instance_create_delete + + - name: Delete networking resources + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_networking_resources + vars: + ec2_networking_resources_operation: delete + ec2_networking_resources_vpc_name: "{{ vpc_name }}" diff --git a/extensions/patterns/configure_ec2/setup.yml b/extensions/patterns/configure_ec2/setup.yml new file mode 100644 index 00000000..468a8043 --- /dev/null +++ b/extensions/patterns/configure_ec2/setup.yml @@ -0,0 +1,61 @@ +--- +controller_labels: + - name: cloud.aws_ops + organization: "{{ organization | default('Default') }}" + - name: configure_ec2_pattern + organization: "{{ organization | default('Default') }}" + - name: create_ec2_instance + organization: "{{ organization | default('Default') }}" + - name: terminate_ec2_instance + organization: "{{ organization | default('Default') }}" + +controller_projects: + - name: AWS Operations / Configure EC2 Instance Pattern Project + organization: "{{ organization | default('Default') }}" + scm_branch: cloud-pattern-testing + scm_clean: no + scm_delete_on_update: no + scm_type: git + scp_update_on_launch: no + scm_url: https://github.com/hakbailey/cloud.aws_ops.git + +controller_templates: + - name: AWS Operations / Create EC2 Instance + description: This job template creates an EC2 instance and associated networking resources. + ask_inventory_on_launch: true + ask_credential_on_launch: true + ask_verbosity_on_launch: true + execution_environment: AWS Operations / Configure EC2 Instance Pattern Execution Environment + project: AWS Operations / Configure EC2 Instance Pattern Project + playbook: extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml + job_type: run + organization: "{{ organization }}" + labels: + - cloud.aws_ops + - configure_ec2_pattern + - create_ec2_instance + survey_enabled: true + survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/create_ec2_instance.yml') | from_yaml }}" + + - name: AWS Operations / Terminate EC2 Instance + description: This job template terminates an EC2 instance and its associated networking resources. + ask_inventory_on_launch: true + ask_credential_on_launch: true + ask_verbosity_on_launch: true + execution_environment: AWS Operations / Configure EC2 Instance Pattern Execution Environment + project: AWS Operations / Configure EC2 Instance Pattern Project + playbook: extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml + job_type: run + organization: "{{ organization }}" + labels: + - cloud.aws_ops + - configure_ec2_pattern + - terminate_ec2_instance + survey_enabled: true + survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/terminate_ec2_instance.yml') | from_yaml }}" + +controller_execution_environments: + - name: AWS Operations / Configure EC2 Instance Pattern Execution Environment + description: Execution environment for the Configure EC2 Instance Pattern + image: docker.io/hakbailey/aws_ops-ee:latest + pull: always diff --git a/extensions/patterns/configure_ec2/template_surveys/create_ec2_instance.yml b/extensions/patterns/configure_ec2/template_surveys/create_ec2_instance.yml new file mode 100644 index 00000000..65f336ca --- /dev/null +++ b/extensions/patterns/configure_ec2/template_surveys/create_ec2_instance.yml @@ -0,0 +1,97 @@ +--- +name: Create EC2 Instance Survey +description: Survey to configure the EC2 instance creation pattern +spec: + - type: text + question_name: AWS Region + question_description: AWS region where resources should be created + variable: aws_region + required: true + + - type: text + question_name: Instance Name + question_description: Name of EC2 instance to create + variable: instance_name + required: true + + - type: text + question_name: Instance Type + question_description: Type of EC2 instance to create (e.g., t2.micro, m5.large) + variable: instance_type + required: true + + - type: text + question_name: AMI ID + question_description: Amazon Machine Image (AMI) ID to use for the instance, if not provided will default to the RHEL 9 AMI for the provided region and instance type + variable: ami_id + required: false + + - type: text + question_name: Key Pair Name + question_description: Name of key pair to use or create for SSH access to the EC2 instance. Defaults to '{{ instance_name }}-key' + variable: key_name + required: false + + - type: multiplechoice + question_name: Wait for State + question_description: Whether to wait for the EC2 instance to be in the running state before continuing. Defaults to true + variable: wait_for_state + required: false + choices: + - "true" + - "false" + + - type: text + question_name: Instance Tags + question_description: 'A dict of tags for the instance, e.g. {"environment: test", "owner": "team foobar"}' + variable: instance_tags + required: false + + - type: text + question_name: VPC Name + question_description: Name of the VPC to create. Defaults to '{{instance_name}}-vpc' + variable: vpc_name + required: false + + - type: text + question_name: VPC CIDR Block + question_description: CIDR block to use for the VPC being created. Defaults to 10.0.0.0/24 + variable: vpc_cidr + required: false + + - type: text + question_name: Subnet CIDR block + question_description: CIDR block to use for the subnet being created. 10.0.0.0/25 + variable: subnet_cidr + required: false + + - type: text + question_name: Security Group Name + question_description: Name of the security group to create for securing traffic to the instance. Defaults to '{{ instance_name }}-sg' + variable: sg_name + required: false + + - type: text + question_name: Security Group Description + question_description: Description for the security group. Defaults to 'Security group for EC2 instance {{ instance_name }}' + variable: sg_description + required: false + + - type: textarea + question_name: Security Group Rules + question_description: "A list of security group rules in yaml format, e.g.: + - proto: tcp + ports: 80 + cidr_ip: 0.0.0.0/0 + Defaults to allowing SSH access from within the VPC" + variable: sg_rules + required: false + + - type: multiplechoice + question_name: Create External Access Resources + question_description: Whether to create resources for external access to the EC2 instance. Defaults to true. When true, adds security groups rules allowing inbound HTTP and HTTPS traffic, creates an internet gateway, creates a custom route table routing all internet traffic to the gateway, and allocates an elastic IP address for the instance. + variable: external_access + required: false + choices: + - "true" + - "false" diff --git a/extensions/patterns/configure_ec2/template_surveys/terminate_ec2_instance.yml b/extensions/patterns/configure_ec2/template_surveys/terminate_ec2_instance.yml new file mode 100644 index 00000000..5c7b5856 --- /dev/null +++ b/extensions/patterns/configure_ec2/template_surveys/terminate_ec2_instance.yml @@ -0,0 +1,21 @@ +--- +name: Terminate EC2 Instance Survey +description: Survey to configure the EC2 instance termination pattern +spec: + - type: text + question_name: AWS Region + question_description: Name of AWS region to create instance in + variable: aws_region + required: true + + - type: text + question_name: Instance Name + question_description: Name of EC2 instance + variable: instance_name + required: true + + - type: text + question_name: Key Pair Name + question_description: Name of key pair for instance, include to delete key pair created with other instance resources. Defaults to '{{ instance_name }}-key' + variable: key_name + required: false From 1c865b581a314846c4145f3af1a4c4401611f9a8 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Thu, 5 Dec 2024 20:37:48 -0500 Subject: [PATCH 08/15] Remove experiences directory which was replace by patterns --- .../template_rhdh/configure_ec2.yml} | 0 extensions/patterns/ec2_instance/README.md | 53 ------- .../exec_env/execution-environment.yml | 29 ---- .../playbooks/create_ec2_instance.yml | 60 -------- .../ec2_instance/playbooks/group_vars/all.yml | 14 -- .../playbooks/terminate_ec2_instance.yml | 12 -- extensions/patterns/ec2_instance/setup.yml | 54 ------- .../template_surveys/create_ec2_instance.yml | 142 ------------------ .../terminate_ec2_instance.yml | 14 -- 9 files changed, 378 deletions(-) rename extensions/patterns/{ec2_instance/template_rhdh/ec2_instance.yaml => configure_ec2/template_rhdh/configure_ec2.yml} (100%) delete mode 100644 extensions/patterns/ec2_instance/README.md delete mode 100644 extensions/patterns/ec2_instance/exec_env/execution-environment.yml delete mode 100644 extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml delete mode 100644 extensions/patterns/ec2_instance/playbooks/group_vars/all.yml delete mode 100644 extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml delete mode 100644 extensions/patterns/ec2_instance/setup.yml delete mode 100644 extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml delete mode 100644 extensions/patterns/ec2_instance/template_surveys/terminate_ec2_instance.yml diff --git a/extensions/patterns/ec2_instance/template_rhdh/ec2_instance.yaml b/extensions/patterns/configure_ec2/template_rhdh/configure_ec2.yml similarity index 100% rename from extensions/patterns/ec2_instance/template_rhdh/ec2_instance.yaml rename to extensions/patterns/configure_ec2/template_rhdh/configure_ec2.yml diff --git a/extensions/patterns/ec2_instance/README.md b/extensions/patterns/ec2_instance/README.md deleted file mode 100644 index 525bf5a2..00000000 --- a/extensions/patterns/ec2_instance/README.md +++ /dev/null @@ -1,53 +0,0 @@ -# Create EC2 Instance Pattern - -## Description - -This pattern is designed to help get an EC2 instance up and running. - -## What This Pattern Covers - -### Projects - -- **AWS Operations / EC2 Instance Patterns**: Defined in `setup.yml`, this project helps organize and manage all necessary components for the ec2 creation pattern. It ensures that relevant files, roles, and configurations are logically arranged, making it easier to maintain and execute automation tasks. - -### Job Templates - -- **AWS Operations / Create EC2 Instance**: This job template is designed to streamline the process of creating an EC2 instance. -- **AWS Operations / Terminate EC2 Instance**: This job template is designed to streamline the process of terminating (deleting) an EC2 instance. - -### Playbooks - -- **Create EC2 Instance Playbook**: This playbook creates an EC2 instance with optional configurations. -- **Terminate EC2 Instance Job Template**: This playbook terminates (deletes) an existing EC2 instance. - -### Surveys - -- **Create EC2 Instance Survey**: This survey provides an interactive way to specify parameters for creating the EC2 instance. -- **Terminate EC2 Instance Survey**: This survey provides an interactive way to specify parameters for terminating the EC2 instance. - -## Resources Created by This Pattern - -1. **Project** - - Ensures that all relevant files, roles, and configurations are logically arranged, facilitating easier maintenance and execution of automation tasks. - -2. **Job Templates** - - Outline the necessary parameters and configurations to perform network backups using the provided playbooks. - - Provide surveys for specifying parameters needed to run the job templates. - -## How to Use - -1. **Use Seed Red Hat Pattern Job** - - Ensure the custom EE is correctly built and available in your Ansible Automation Platform. Execute the "Seed Red Hat Pattern" job within the Ansible Automation Platform, and select the "AWS Operations" category to load this pattern. - -2. **Use the Job Templates** - - In the `AWS Operations / EC2 Instance Patterns` execute the required job template to create the EC2 instance. Monitor the job execution and verify that the instance has been successfully created. - -## Contribution - -Contributions to this project are welcome. Please fork the repository, make your changes, and submit a pull request. - -## License - -GNU General Public License v3.0 or later. - -See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text. This project is licensed under the MIT License. See the [LICENSE](https://github.com/redhat-cop/cloud.aws_ops/blob/main/LICENSE) file for details. diff --git a/extensions/patterns/ec2_instance/exec_env/execution-environment.yml b/extensions/patterns/ec2_instance/exec_env/execution-environment.yml deleted file mode 100644 index f7bceb39..00000000 --- a/extensions/patterns/ec2_instance/exec_env/execution-environment.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -version: 3 - -dependencies: - ansible_core: - package_pip: ansible-core - ansible_runner: - package_pip: ansible-runner - galaxy: - collections: - - name: cloud.aws_ops - source: https://github.com/hakbailey/cloud.aws_ops.git - type: git - version: cloud-pattern-testing - - name: amazon.aws - source: https://github.com/ansible-collections/amazon.aws.git - type: git - version: main - python: - - boto3 - - botocore - -images: - base_image: - name: docker.io/redhat/ubi9:latest - -additional_build_steps: - append_base: | - RUN yum install -y git diff --git a/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml b/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml deleted file mode 100644 index cb4611ec..00000000 --- a/extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml +++ /dev/null @@ -1,60 +0,0 @@ ---- -- name: Create EC2 instance - hosts: localhost - gather_facts: false - module_defaults: - group/aws: - aws_region: "{{ aws_region }}" - tasks: - - name: Get AMIs for operating system and region - amazon.aws.ec2_ami_info: - filters: - architecture: x86_64 - name: "{{ os_type }}*" - owner: - - amazon - register: images - - - name: Set variables with dynamic values - ansible.builtin.set_fact: - image_id: "{{ (images.images | sort(attribute='name') | last).image_id }}" - key_name: "{{ key_name | default(instance_name ~ '-key') }}" - instance_tags: "{{ instance_tags | default('{}') | from_json }}" - eip_tags: "{{ eip_tags | default('{}') | from_json }}" - igw_tags: "{{ igw_tags | default('{}') | from_json }}" - sg_name: "{{ sg_name | default(instance_name ~ '-external-sg') }}" - sg_rule_names: "{{ sg_rules | map('split', ':') | map('first') | list }}" - sg_tags: "{{ sg_tags | default('{}') | from_json }}" - - - name: Check whether IP range is specified for SSH access - ansible.builtin.fail: - msg: "Must specify Security Group SSH Rule IP Range when allowing inbound SSH traffic." - when: - '"ssh" in sg_rule_names and sg_ssh_ip | default("", true) == ""' - - - name: Translate sg rules - ansible.builtin.set_fact: - selected_sg_rules: "{{ sg_rule_names | map('extract', sg_rule_options) | list }}" - - - name: Run ec2_instance_create role - ansible.builtin.include_role: - name: cloud.aws_ops.ec2_instance_create - vars: - ec2_instance_create_operation: create - ec2_instance_create_aws_region: "{{ aws_region }}" - ec2_instance_create_instance_name: "{{ instance_name }}" - ec2_instance_create_instance_type: "{{ instance_type }}" - ec2_instance_create_ami_id: "{{ image_id }}" - ec2_instance_create_key_name: "{{ key_name }}" - ec2_instance_create_vpc_id: "{{ vpc_id | default(omit) }}" - ec2_instance_create_vpc_subnet_id: "{{ subnet_id | default(omit) }}" - ec2_instance_create_tags: "{{ instance_tags | default(omit) }}" - ec2_instance_create_wait_for_boot: "{{ wait_for_boot | bool }}" - ec2_instance_create_associate_eip: "{{ associate_eip | bool }}" - ec2_instance_create_eip_tags: "{{ eip_tags | default(omit) }}" - ec2_instance_create_associate_igw: "{{ associate_igw | bool }}" - ec2_instance_create_igw_tags: "{{ igw_tags | default(omit) }}" - ec2_instance_create_associate_external_sg: "{{ associate_sg | bool }}" - ec2_instance_create_external_sg_name: "{{ sg_name }}" - ec2_instance_create_external_sg_description: "{{ sg_description }}" - ec2_instance_create_external_sg_rules: "{{ selected_sg_rules }}" diff --git a/extensions/patterns/ec2_instance/playbooks/group_vars/all.yml b/extensions/patterns/ec2_instance/playbooks/group_vars/all.yml deleted file mode 100644 index ffb01bb9..00000000 --- a/extensions/patterns/ec2_instance/playbooks/group_vars/all.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -sg_rule_options: - http: - proto: tcp - ports: "80" - cidr_ip: 0.0.0.0/0 - https: - proto: tcp - ports: "443" - cidr_ip: 0.0.0.0/0 - ssh: - proto: tcp - ports: "22" - cidr_ip: "{{ sg_ssh_ip }}" diff --git a/extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml b/extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml deleted file mode 100644 index 2e242cbd..00000000 --- a/extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Terminate EC2 instance - hosts: localhost - gather_facts: false - tasks: - - name: Run ec2_instance_create role - ansible.builtin.include_role: - name: cloud.aws_ops.ec2_instance_create - vars: - ec2_instance_create_operation: delete - ec2_instance_create_aws_region: "{{ aws_region }}" - ec2_instance_create_instance_name: "{{ instance_name }}" diff --git a/extensions/patterns/ec2_instance/setup.yml b/extensions/patterns/ec2_instance/setup.yml deleted file mode 100644 index 9515ea67..00000000 --- a/extensions/patterns/ec2_instance/setup.yml +++ /dev/null @@ -1,54 +0,0 @@ ---- -controller_labels: - - name: cloud.aws_ops - organization: "{{ organization | default('Default') }}" - - name: ec2_instance_pattern - organization: "{{ organization | default('Default') }}" - - name: create_ec2_instance - organization: "{{ organization | default('Default') }}" - - name: terminate_ec2_instance - organization: "{{ organization | default('Default') }}" - -controller_projects: - - name: AWS Operations / EC2 Instance Patterns - organization: "{{ organization | default('Default') }}" - scm_branch: cloud-pattern-testing - scm_clean: no - scm_delete_on_update: no - scm_type: git - scp_update_on_launch: no - scm_url: https://github.com/hakbailey/cloud.aws_ops.git - -controller_templates: - - name: AWS Operations / Create EC2 Instance - description: This job template creates an EC2 instance. - ask_inventory_on_launch: true - ask_execution_environment_on_launch: true - ask_credential_on_launch: true - ask_verbosity_on_launch: true - project: AWS Operations / EC2 Instance Patterns - playbook: extensions/patterns/ec2_instance/playbooks/create_ec2_instance.yml - job_type: run - organization: "{{ organization }}" - labels: - - cloud.aws_ops - - ec2_instance_pattern - - create_ec2_instance - survey_enabled: true - survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/create_ec2_instance.yml') | from_yaml }}" - - name: AWS Operations / Terminate EC2 Instance - description: This job template terminates an EC2 instance. - ask_inventory_on_launch: true - ask_execution_environment_on_launch: true - ask_credential_on_launch: true - ask_verbosity_on_launch: true - project: AWS Operations / EC2 Instance Patterns - playbook: extensions/patterns/ec2_instance/playbooks/terminate_ec2_instance.yml - job_type: run - organization: "{{ organization }}" - labels: - - cloud.aws_ops - - ec2_instance_pattern - - terminate_ec2_instance - survey_enabled: true - survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/terminate_ec2_instance.yml') | from_yaml }}" diff --git a/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml b/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml deleted file mode 100644 index 21e07577..00000000 --- a/extensions/patterns/ec2_instance/template_surveys/create_ec2_instance.yml +++ /dev/null @@ -1,142 +0,0 @@ ---- -name: Create EC2 Instance Survey -description: Survey to configure the EC2 instance creation pattern -spec: - - type: text - question_name: AWS Region - question_description: Name of AWS region to create instance in - variable: aws_region - required: true - - - type: text - question_name: Instance Name - question_description: Name of EC2 instance - variable: instance_name - required: true - - - type: text - question_name: Instance Type - question_description: Type of EC2 instance (e.g., t2.micro, m5.large) - variable: instance_type - required: true - - - type: multiplechoice - question_name: Operating system image - question_description: Amazon Machine Image to use for the instance - variable: os_type - required: false - default: RHEL-9 - choices: - - RHEL-9 - - Windows_Server-2025-English-Full-Base - - - type: text - question_name: Key Pair Name - question_description: Name of key pair to use or create for SSH access to the EC2 instance, if not provided defaults to '{instance-name}-key' - variable: key_name - required: false - - - type: text - question_name: VPC ID - question_description: ID of VPC to launch EC2 instance and associated networking resources in, if not provided will launch in the default VPC for the region - variable: vpc_id - required: false - - - type: text - question_name: VPC Subnet ID - question_description: ID of subnet to launch EC2 instance in, if not provided will launch in the default zone of the VPC - variable: subnet_id - required: false - - - type: multiplechoice - question_name: Wait for Boot - question_description: Whether to wait for the EC2 instance to be in the running state before continuing, defaults to true - variable: wait_for_boot - required: false - default: "true" - choices: - - "true" - - "false" - - - type: text - question_name: Instance Tags - question_description: 'A dict of tags for the instance, e.g. {"environment: test", "owner": "team foobar"}' - variable: instance_tags - required: false - - - type: multiplechoice - question_name: Associate EIP - question_description: Whether to create and associate an Elastic IP (EIP) with the EC2 instance - variable: associate_eip - required: false - default: "false" - choices: - - "true" - - "false" - - - type: text - question_name: EIP Tags - question_description: 'A dict of tags for the EIP, e.g. {"environment: test", "owner": "team foobar"}' - variable: eip_tags - required: false - - - type: multiplechoice - question_name: Associate Internet Gateway - question_description: Whether to create and associate an internet gateway - variable: associate_igw - required: false - default: "false" - choices: - - "true" - - "false" - - - type: text - question_name: Internet Gateway Tags - question_description: 'A dict of tags for the internet gateway, e.g. {"environment: test", "owner": "team foobar"}' - variable: igw_tags - required: false - - - type: multiplechoice - question_name: Associate Security Group - question_description: Whether to create and associate a security group for external access - variable: associate_sg - required: false - default: "false" - choices: - - "true" - - "false" - - - type: text - question_name: Security Group Name - question_description: Name of the security group to create, defaults to '{instance_name}-external-sg' - variable: sg_name - required: false - - - type: text - question_name: Security Group description - question_description: Description for the security group, will only be used if a new security group is created - variable: sg_description - required: false - default: Security group for external access - - - type: multiselect - question_name: Security Group Rules - question_description: Rules for the security group - variable: sg_rules - required: false - choices: - - 'http: Allow inbound HTTP traffic from all IPv4 addresses' - - 'https: Allow inbound HTTPS access from all IPv4 addresses' - - 'ssh: Allow inbound SSH access from an IPv4 IP address range (must specify Security Group SSH Rule IP Range)' - - - type: text - question_name: Security Group SSH Rule IP Range - question_description: IPv4 address range from which to allow inbound SSH traffic - variable: sg_ssh_ip - required: false - - - type: text - question_name: Security Group Tags - question_description: 'A dict of tags for the security group, e.g. {"environment: test", "owner": "team foobar"}, will only be used if a new security group is created' - variable: sg_tags - required: false diff --git a/extensions/patterns/ec2_instance/template_surveys/terminate_ec2_instance.yml b/extensions/patterns/ec2_instance/template_surveys/terminate_ec2_instance.yml deleted file mode 100644 index 3c9f9adc..00000000 --- a/extensions/patterns/ec2_instance/template_surveys/terminate_ec2_instance.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -name: Terminate EC2 Instance Survey -description: Survey to configure the EC2 instance termination pattern -spec: - - type: text - question_name: AWS Region - question_description: Name of AWS region to create instance in - variable: aws_region - required: true - - type: text - question_name: Instance Name - question_description: Name of EC2 instance - variable: ec2_instance_create_instance_name - required: true From a5f972b8b395eda723cad9026120532c413089cd Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Thu, 5 Dec 2024 20:48:02 -0500 Subject: [PATCH 09/15] Fix linter error --- extensions/patterns/configure_ec2/playbooks/group_vars/all.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml b/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml index aacd5d9c..34bf6822 100644 --- a/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml +++ b/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml @@ -15,6 +15,6 @@ allow_external_access_sg_rules: - proto: tcp ports: 80 cidr_ip: 0.0.0.0/0 - - ports: tcp + - proto: tcp ports: 443 cidr_ip: 0.0.0.0/0 From be3dd183c208f0d701783ad614778d32df06c97f Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Thu, 5 Dec 2024 20:52:22 -0500 Subject: [PATCH 10/15] More linter fixes --- .../patterns/configure_ec2/playbooks/create_ec2_instance.yml | 2 +- extensions/patterns/configure_ec2/playbooks/group_vars/all.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml b/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml index 25b10b21..5ff52220 100644 --- a/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml +++ b/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml @@ -53,6 +53,6 @@ ec2_instance_create_delete_key_name: "{{ key_name }}" ec2_instance_create_delete_vpc_subnet_id: "{{ ec2_networking_resources_subnet_result.subnet.id }}" ec2_instance_create_delete_wait_for_state: "{{ wait_for_state | bool }}" - ec2_instance_create_delete_associate_security_groups: "{{ [ sg_name ] }}" + ec2_instance_create_delete_associate_security_groups: "{{ [sg_name] }}" ec2_instance_create_delete_associate_eip: "{{ create_external_access_resources }}" ec2_instance_create_delete_instance_tags: "{{ instance_tags | default('{}', true) | from_json }}" diff --git a/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml b/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml index 34bf6822..14360fcc 100644 --- a/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml +++ b/extensions/patterns/configure_ec2/playbooks/group_vars/all.yml @@ -1,6 +1,6 @@ key_name: "{{ instance_name }}-key" wait_for_state: true -vpc_name: "{{instance_name}}-vpc" +vpc_name: "{{ instance_name }}-vpc" vpc_cidr: 10.0.0.0/24 subnet_cidr: 10.0.0.0/25 sg_name: "{{ instance_name }}-sg" From 720bf965f1cd4bb08a8ece6fa0e70331a41f7897 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Thu, 5 Dec 2024 20:57:25 -0500 Subject: [PATCH 11/15] Remove references to personal repo --- .../patterns/configure_ec2/exec_env/execution-environment.yml | 4 ++-- extensions/patterns/configure_ec2/setup.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/patterns/configure_ec2/exec_env/execution-environment.yml b/extensions/patterns/configure_ec2/exec_env/execution-environment.yml index f7bceb39..0fbc807b 100644 --- a/extensions/patterns/configure_ec2/exec_env/execution-environment.yml +++ b/extensions/patterns/configure_ec2/exec_env/execution-environment.yml @@ -9,9 +9,9 @@ dependencies: galaxy: collections: - name: cloud.aws_ops - source: https://github.com/hakbailey/cloud.aws_ops.git + source: https://github.com/redhat-cop/cloud.aws_ops.git type: git - version: cloud-pattern-testing + version: main - name: amazon.aws source: https://github.com/ansible-collections/amazon.aws.git type: git diff --git a/extensions/patterns/configure_ec2/setup.yml b/extensions/patterns/configure_ec2/setup.yml index 468a8043..22e97c3c 100644 --- a/extensions/patterns/configure_ec2/setup.yml +++ b/extensions/patterns/configure_ec2/setup.yml @@ -12,12 +12,12 @@ controller_labels: controller_projects: - name: AWS Operations / Configure EC2 Instance Pattern Project organization: "{{ organization | default('Default') }}" - scm_branch: cloud-pattern-testing + scm_branch: main scm_clean: no scm_delete_on_update: no scm_type: git scp_update_on_launch: no - scm_url: https://github.com/hakbailey/cloud.aws_ops.git + scm_url: https://github.com/redhat-cop/cloud.aws_ops.git controller_templates: - name: AWS Operations / Create EC2 Instance From 31ef84385759ca3608316693fd204e5e968296b1 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Fri, 6 Dec 2024 09:32:50 -0500 Subject: [PATCH 12/15] Add vpc_name to terminate survey --- .../template_surveys/terminate_ec2_instance.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/extensions/patterns/configure_ec2/template_surveys/terminate_ec2_instance.yml b/extensions/patterns/configure_ec2/template_surveys/terminate_ec2_instance.yml index 5c7b5856..0678b4ee 100644 --- a/extensions/patterns/configure_ec2/template_surveys/terminate_ec2_instance.yml +++ b/extensions/patterns/configure_ec2/template_surveys/terminate_ec2_instance.yml @@ -19,3 +19,9 @@ spec: question_description: Name of key pair for instance, include to delete key pair created with other instance resources. Defaults to '{{ instance_name }}-key' variable: key_name required: false + + - type: text + question_name: VPC Name + question_description: Name of the VPC to delete, include to delete VPC and associated networking resources created for instance. Defaults to '{{instance_name}}-vpc' + variable: vpc_name + required: false From df2d70bcb83a2c3d705f54274b30a0c3ae468608 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Fri, 6 Dec 2024 10:18:55 -0500 Subject: [PATCH 13/15] Update ec2 instance role name --- .../playbooks/create_ec2_instance.yml | 22 +++++++++---------- .../playbooks/terminate_ec2_instance.yml | 10 ++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml b/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml index 5ff52220..0f9f1020 100644 --- a/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml +++ b/extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml @@ -44,15 +44,15 @@ - name: Create EC2 instance ansible.builtin.include_role: - name: cloud.aws_ops.ec2_instance_create_delete + name: cloud.aws_ops.manage_ec2_instance vars: - ec2_instance_create_delete_operation: create - ec2_instance_create_delete_instance_name: "{{ instance_name }}" - ec2_instance_create_delete_instance_type: "{{ instance_type }}" - ec2_instance_create_delete_ami_id: "{{ ami_id }}" - ec2_instance_create_delete_key_name: "{{ key_name }}" - ec2_instance_create_delete_vpc_subnet_id: "{{ ec2_networking_resources_subnet_result.subnet.id }}" - ec2_instance_create_delete_wait_for_state: "{{ wait_for_state | bool }}" - ec2_instance_create_delete_associate_security_groups: "{{ [sg_name] }}" - ec2_instance_create_delete_associate_eip: "{{ create_external_access_resources }}" - ec2_instance_create_delete_instance_tags: "{{ instance_tags | default('{}', true) | from_json }}" + manage_ec2_instance_operation: create + manage_ec2_instance_instance_name: "{{ instance_name }}" + manage_ec2_instance_instance_type: "{{ instance_type }}" + manage_ec2_instance_ami_id: "{{ ami_id }}" + manage_ec2_instance_key_name: "{{ key_name }}" + manage_ec2_instance_vpc_subnet_id: "{{ ec2_networking_resources_subnet_result.subnet.id }}" + manage_ec2_instance_wait_for_state: "{{ wait_for_state | bool }}" + manage_ec2_instance_associate_security_groups: "{{ [sg_name] }}" + manage_ec2_instance_associate_eip: "{{ create_external_access_resources }}" + manage_ec2_instance_instance_tags: "{{ instance_tags | default('{}', true) | from_json }}" diff --git a/extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml b/extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml index a8668b5a..13e23293 100644 --- a/extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml +++ b/extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml @@ -6,15 +6,15 @@ group/aws: aws_region: "{{ aws_region }}" tasks: - - name: Set ec2_instance_create_delete role vars + - name: Set manage_ec2_instance role vars ansible.builtin.set_fact: - ec2_instance_create_delete_operation: delete - ec2_instance_create_delete_instance_name: "{{ instance_name }}" - ec2_instance_create_delete_key_name: "{{ key_name | default(omit, true) }}" + manage_ec2_instance_operation: delete + manage_ec2_instance_instance_name: "{{ instance_name }}" + manage_ec2_instance_key_name: "{{ key_name | default(omit, true) }}" - name: Delete EC2 instance ansible.builtin.include_role: - name: cloud.aws_ops.ec2_instance_create_delete + name: cloud.aws_ops.manage_ec2_instance - name: Delete networking resources ansible.builtin.include_role: From e32e8f89f0b04ea803e1dea2e3ffc959ac376700 Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Fri, 6 Dec 2024 10:57:56 -0500 Subject: [PATCH 14/15] Set project to update on launch --- extensions/patterns/configure_ec2/setup.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/patterns/configure_ec2/setup.yml b/extensions/patterns/configure_ec2/setup.yml index 22e97c3c..c97a6578 100644 --- a/extensions/patterns/configure_ec2/setup.yml +++ b/extensions/patterns/configure_ec2/setup.yml @@ -13,10 +13,10 @@ controller_projects: - name: AWS Operations / Configure EC2 Instance Pattern Project organization: "{{ organization | default('Default') }}" scm_branch: main - scm_clean: no - scm_delete_on_update: no + scm_clean: false + scm_delete_on_update: false scm_type: git - scp_update_on_launch: no + scm_update_on_launch: true scm_url: https://github.com/redhat-cop/cloud.aws_ops.git controller_templates: From c06206a755b64ad2129df67149bed2a51370edfe Mon Sep 17 00:00:00 2001 From: Helen Bailey Date: Mon, 9 Dec 2024 09:07:41 -0500 Subject: [PATCH 15/15] Add default org in setup file --- extensions/patterns/configure_ec2/setup.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/patterns/configure_ec2/setup.yml b/extensions/patterns/configure_ec2/setup.yml index c97a6578..c0d5484b 100644 --- a/extensions/patterns/configure_ec2/setup.yml +++ b/extensions/patterns/configure_ec2/setup.yml @@ -29,7 +29,7 @@ controller_templates: project: AWS Operations / Configure EC2 Instance Pattern Project playbook: extensions/patterns/configure_ec2/playbooks/create_ec2_instance.yml job_type: run - organization: "{{ organization }}" + organization: "{{ organization | default('Default') }}" labels: - cloud.aws_ops - configure_ec2_pattern @@ -46,7 +46,7 @@ controller_templates: project: AWS Operations / Configure EC2 Instance Pattern Project playbook: extensions/patterns/configure_ec2/playbooks/terminate_ec2_instance.yml job_type: run - organization: "{{ organization }}" + organization: "{{ organization | default('Default') }}" labels: - cloud.aws_ops - configure_ec2_pattern