From 78ebb329f51a66e359c7737f4c016b176213b93d Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 18 Nov 2024 14:39:52 -0500 Subject: [PATCH 01/17] Add experience for creating AWS EC2 instance with all the necessary network configurations --- changelogs/fragments/add_configure_ec2_experience.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/add_configure_ec2_experience.yml diff --git a/changelogs/fragments/add_configure_ec2_experience.yml b/changelogs/fragments/add_configure_ec2_experience.yml new file mode 100644 index 00000000..a72d0e98 --- /dev/null +++ b/changelogs/fragments/add_configure_ec2_experience.yml @@ -0,0 +1,2 @@ +minor_changes: + - Add experience for creating AWS EC2 instance with all the necessary network configurations. From 0877f94873936cf82e17e4cffaf554267fc65b1b Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Wed, 20 Nov 2024 11:30:04 -0500 Subject: [PATCH 02/17] Add experience --- .../experiences/configure_ec2/README.md | 0 .../configure_ec2/group_vars/all.yaml | 4 ++ .../playbooks/run_configure_ec2.yml | 28 +++++++++++++ .../experiences/configure_ec2/setup.yml | 41 +++++++++++++++++++ .../template_surveys/configure_ec2.yaml | 0 5 files changed, 73 insertions(+) create mode 100644 extensions/experiences/configure_ec2/README.md create mode 100644 extensions/experiences/configure_ec2/group_vars/all.yaml create mode 100644 extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yml create mode 100644 extensions/experiences/configure_ec2/setup.yml create mode 100644 extensions/experiences/configure_ec2/template_surveys/configure_ec2.yaml diff --git a/extensions/experiences/configure_ec2/README.md b/extensions/experiences/configure_ec2/README.md new file mode 100644 index 00000000..e69de29b diff --git a/extensions/experiences/configure_ec2/group_vars/all.yaml b/extensions/experiences/configure_ec2/group_vars/all.yaml new file mode 100644 index 00000000..9f0638fa --- /dev/null +++ b/extensions/experiences/configure_ec2/group_vars/all.yaml @@ -0,0 +1,4 @@ +--- +organization: Default +# Github PAT +scm_credential: "UserGHPAT" diff --git a/extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yml b/extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yml new file mode 100644 index 00000000..e370eb63 --- /dev/null +++ b/extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yml @@ -0,0 +1,28 @@ +--- +- name: Create AWS EC2 instance with the necessary network configurations + hosts: localhost + gather_facts: false + tasks: + - name: Configure Network resources + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_networking_resources + vars: + ec2_networking_resources_vpc_name: "{{ vpc_name }}" + ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" + ec2_networking_resources_subnet_cidr_block: "{{ subnet }}" + ec2_networking_resources_sg_internal_name: "{{ security_group_internal }}" + ec2_networking_resources_sg_internal_description: "{{ security_group_internal_description }}" + + - name: Configure AWS EC2 instance + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_instance_create + vars: + ec2_instance_create_aws_region: "{{ region }}" + ec2_instance_create_instance_name: "{{ instance_name }}" + ec2_instance_create_instance_type: "{{ instance_type }}" + ec2_instance_create_ami_id: "{{ ami_id }}" + ec2_instance_create_vpc_subnet_id: subnet-071443aa123456789 + ec2_instance_create_tags: + Component: my-test-instance + Environment: Testing + ec2_instance_create_wait_for_boot: true diff --git a/extensions/experiences/configure_ec2/setup.yml b/extensions/experiences/configure_ec2/setup.yml new file mode 100644 index 00000000..1791d1f7 --- /dev/null +++ b/extensions/experiences/configure_ec2/setup.yml @@ -0,0 +1,41 @@ +--- +# Labels +# +controller_labels: + - name: cloud.aws_ops + organization: "{{ organization }}" + - name: confgiure_ec2_experience + organization: "{{ organization }}" + - name: run_configure_ec2 + organization: "{{ organization }}" + +# Projects +# +controller_projects: + - name: AWS Operations / Configure EC2 Experience Project + organization: "{{ organization }}" + scm_branch: main + scm_clean: 'no' + scm_delete_on_update: 'no' + scm_type: git + scm_update_on_launch: 'no' + scm_credential: "{{ scm_credential }}" + scm_url: https://github.com/GomathiselviS/cloud.aws_ops.git + + +# Job Templates +# +controller_templates: + - name: AWS Operations / Configure EC2 instance + description: This job template creates an EC2 instance with the necessary network infrastructure + project: AWS Operations / Configure EC2 Experience Project + playbook: extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yaml + job_type: "run" + organization: "{{ organization | default('Default') }}" + labels: + - cloud.aws_ops + - configure_ec2_experience + - run_configure_ec2 + credentials: aws-instance + survey_enabled: true + survey_spec: "{{ lookup('file', experience.path.replace('setup.yml', '') + 'template_surveys/configure_ec2.yaml') | from_yaml }}" diff --git a/extensions/experiences/configure_ec2/template_surveys/configure_ec2.yaml b/extensions/experiences/configure_ec2/template_surveys/configure_ec2.yaml new file mode 100644 index 00000000..e69de29b From 268a94cbb46eaea97bb64e2351e385a9e3166819 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Wed, 20 Nov 2024 22:59:51 -0500 Subject: [PATCH 03/17] Add survey --- .../README.md | 0 .../group_vars/all.yaml | 0 .../playbooks/run_configure_aws_network.yml | 44 ++++++++ .../setup.yml | 20 ++-- .../configure_aws_network.yaml | 103 ++++++++++++++++++ .../playbooks/run_configure_ec2.yml | 28 ----- .../template_surveys/configure_ec2.yaml | 0 7 files changed, 157 insertions(+), 38 deletions(-) rename extensions/experiences/{configure_ec2 => configure_aws_network}/README.md (100%) rename extensions/experiences/{configure_ec2 => configure_aws_network}/group_vars/all.yaml (100%) create mode 100644 extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml rename extensions/experiences/{configure_ec2 => configure_aws_network}/setup.yml (53%) create mode 100644 extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml delete mode 100644 extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yml delete mode 100644 extensions/experiences/configure_ec2/template_surveys/configure_ec2.yaml diff --git a/extensions/experiences/configure_ec2/README.md b/extensions/experiences/configure_aws_network/README.md similarity index 100% rename from extensions/experiences/configure_ec2/README.md rename to extensions/experiences/configure_aws_network/README.md diff --git a/extensions/experiences/configure_ec2/group_vars/all.yaml b/extensions/experiences/configure_aws_network/group_vars/all.yaml similarity index 100% rename from extensions/experiences/configure_ec2/group_vars/all.yaml rename to extensions/experiences/configure_aws_network/group_vars/all.yaml diff --git a/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml b/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml new file mode 100644 index 00000000..5fc463c7 --- /dev/null +++ b/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml @@ -0,0 +1,44 @@ +--- +- name: Create necessary network resources + hosts: localhost + gather_facts: false + tasks: + - name: Create a list of dictionaries for security group rules + ansible.builtin.set_fact: + sg_internal_rules: >- + {{ + [ + { + 'proto': security_group_1_proto, + 'ports': security_group_1_port, + 'cidr_ip': security_group_1_cidr + }, + { + 'proto': security_group_2_proto, + 'ports': security_group_2_port, + 'cidr_ip': security_group_2_cidr + }, + { + 'proto': security_group_3_proto, + 'ports': security_group_3_port, + 'cidr_ip': security_group_3_cidr + } + ] | selectattr('proto', 'defined') | selectattr('ports', 'defined') | selectattr('cidr_ip', 'defined') | list + }} + + - name: Set default value for the security group rules if nothing is passed. + ansible.builtin.set_fact: + sg_internal_rules: "{{ sg_internal_rules | default([ + {'proto': 'tcp', 'port': '22', 'cidr_ip': vpc_cidr} + ]) }}" + + - name: Configure Network resources + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_networking_resources + vars: + ec2_networking_resources_vpc_name: "{{ vpc_name }}" + ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" + ec2_networking_resources_subnet_cidr_block: "{{ subnet }}" + ec2_networking_resources_sg_internal_name: "{{ security_group_internal }}" + ec2_networking_resources_sg_internal_description: "{{ security_group_internal_description }}" + ec2_networking_resources_sg_internal_rules: "{{ sg_internal_rules }}" diff --git a/extensions/experiences/configure_ec2/setup.yml b/extensions/experiences/configure_aws_network/setup.yml similarity index 53% rename from extensions/experiences/configure_ec2/setup.yml rename to extensions/experiences/configure_aws_network/setup.yml index 1791d1f7..63974b10 100644 --- a/extensions/experiences/configure_ec2/setup.yml +++ b/extensions/experiences/configure_aws_network/setup.yml @@ -4,15 +4,15 @@ controller_labels: - name: cloud.aws_ops organization: "{{ organization }}" - - name: confgiure_ec2_experience + - name: confgiure_aws_network_experience organization: "{{ organization }}" - - name: run_configure_ec2 + - name: run_configure_aws_network organization: "{{ organization }}" # Projects # controller_projects: - - name: AWS Operations / Configure EC2 Experience Project + - name: AWS Operations / Configure AWS Network Experience Project organization: "{{ organization }}" scm_branch: main scm_clean: 'no' @@ -26,16 +26,16 @@ controller_projects: # Job Templates # controller_templates: - - name: AWS Operations / Configure EC2 instance - description: This job template creates an EC2 instance with the necessary network infrastructure - project: AWS Operations / Configure EC2 Experience Project - playbook: extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yaml + - name: AWS Operations / Configure AWS Network for EC2 + description: This job template creates the necessary network infrastructure needed to configure AWS EC2 instance + project: AWS Operations / Configure AWS Network Experience Project + playbook: extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yaml job_type: "run" organization: "{{ organization | default('Default') }}" labels: - cloud.aws_ops - - configure_ec2_experience - - run_configure_ec2 + - configure_aws_network_experience + - run_configure_aws_network credentials: aws-instance survey_enabled: true - survey_spec: "{{ lookup('file', experience.path.replace('setup.yml', '') + 'template_surveys/configure_ec2.yaml') | from_yaml }}" + survey_spec: "{{ lookup('file', experience.path.replace('setup.yml', '') + 'template_surveys/configure_aws_network.yaml') | from_yaml }}" diff --git a/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml b/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml new file mode 100644 index 00000000..0ea327cc --- /dev/null +++ b/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml @@ -0,0 +1,103 @@ +ec2_networking_resources_vpc_name: "{{ vpc_name }}" + ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" + ec2_networking_resources_subnet_cidr_block: "{{ subnet }}" + ec2_networking_resources_sg_internal_name: "{{ security_group_internal }}" + ec2_networking_resources_sg_internal_description: "{{ security_group_internal_description }}" + +--- +name: "AWS Network Configuration Survey" +description: "Survey to configure aws network Rresources to create an EC2 instance" +spec: + - type: "multiplechoice" + question_name: "Backup Type" + question_description: "Select the type of backup" + variable: "backup_type" + choices: + - "full" + - "diff" + required: true + default: "full" + + - type: "text" + question_name: "VPC name" + question_description: "The name of the VPC to create." + variable: "vpc_name" + required: true + + - type: "text" + question_name: "VPC CIDR block" + question_description: "The CIDR block to use for the VPC being created." + variable: "vpc_cidr" + required: true + + - type: "text" + question_name: "Subnet CIDR block" + question_description: "The CIDR block to use for subnet being created." + variable: "subnet" + required: true + + - type: "text" + question_name: "Internal Security Group name" + question_description: "The name of the security group to create." + variable: "security_group_internal" + required: true + + - type: "text" + question_name: "Internal Security Group description" + question_description: "The name of the security group to create." + variable: "security_group_internal" + required: true + + - type: "text" + question_name: "Internal Security Group rule 1 protocol" + question_description: "The IP protocol name. If not provided, ssh will be used" + variable: "security_group_1_proto" + required: false + + - type: "text" + question_name: "Internal Security Group rule 1 port" + question_description: "Port numbers the traffic is going to. Can be a single port, or a range of ports, for example, 8000-8010. If not provided 22 will be used" + variable: "security_group_1_port" + required: false + + - type: "text" + question_name: "Internal Security Group rule 1 cidr block" + question_description: "The CIDR block traffic is coming from. If not provided, cidr block of the vpc created will be used." + variable: "security_group_1_cidr" + required: false + + - type: "text" + question_name: "Internal Security Group rule 2 protocol" + question_description: "The IP protocol name." + variable: "security_group_2_proto" + required: false + + - type: "text" + question_name: "Internal Security Group rule 2 port" + question_description: "Port numbers the traffic is going to. Can be a single port, or a range of ports, for example, 8000-8010." + variable: "security_group_2_port" + required: false + + - type: "text" + question_name: "Internal Security Group rule 2 cidr block" + question_description: "The CIDR block traffic is coming from." + variable: "security_group_2_cidr" + required: false + + - type: "text" + question_name: "Internal Security Group rule 3 protocol" + question_description: "The IP protocol name." + variable: "security_group_3_proto" + required: false + + - type: "text" + question_name: "Internal Security Group rule 3 port" + question_description: "Port numbers the traffic is going to. Can be a single port, or a range of ports, for example, 8000-8010." + variable: "security_group_3_port" + required: false + + - type: "text" + question_name: "Internal Security Group rule 3 cidr block" + question_description: "The CIDR block traffic is coming from." + variable: "security_group_3_cidr" + required: false diff --git a/extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yml b/extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yml deleted file mode 100644 index e370eb63..00000000 --- a/extensions/experiences/configure_ec2/playbooks/run_configure_ec2.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -- name: Create AWS EC2 instance with the necessary network configurations - hosts: localhost - gather_facts: false - tasks: - - name: Configure Network resources - ansible.builtin.include_role: - name: cloud.aws_ops.ec2_networking_resources - vars: - ec2_networking_resources_vpc_name: "{{ vpc_name }}" - ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" - ec2_networking_resources_subnet_cidr_block: "{{ subnet }}" - ec2_networking_resources_sg_internal_name: "{{ security_group_internal }}" - ec2_networking_resources_sg_internal_description: "{{ security_group_internal_description }}" - - - name: Configure AWS EC2 instance - ansible.builtin.include_role: - name: cloud.aws_ops.ec2_instance_create - vars: - ec2_instance_create_aws_region: "{{ region }}" - ec2_instance_create_instance_name: "{{ instance_name }}" - ec2_instance_create_instance_type: "{{ instance_type }}" - ec2_instance_create_ami_id: "{{ ami_id }}" - ec2_instance_create_vpc_subnet_id: subnet-071443aa123456789 - ec2_instance_create_tags: - Component: my-test-instance - Environment: Testing - ec2_instance_create_wait_for_boot: true diff --git a/extensions/experiences/configure_ec2/template_surveys/configure_ec2.yaml b/extensions/experiences/configure_ec2/template_surveys/configure_ec2.yaml deleted file mode 100644 index e69de29b..00000000 From f5d271b93a49c9c5bc036acd4d2b053ce4bfc831 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Fri, 22 Nov 2024 09:33:28 -0500 Subject: [PATCH 04/17] remove scm_credentials --- .../experiences/configure_aws_network/group_vars/all.yaml | 2 -- extensions/experiences/configure_aws_network/setup.yml | 1 - 2 files changed, 3 deletions(-) diff --git a/extensions/experiences/configure_aws_network/group_vars/all.yaml b/extensions/experiences/configure_aws_network/group_vars/all.yaml index 9f0638fa..0441c601 100644 --- a/extensions/experiences/configure_aws_network/group_vars/all.yaml +++ b/extensions/experiences/configure_aws_network/group_vars/all.yaml @@ -1,4 +1,2 @@ --- organization: Default -# Github PAT -scm_credential: "UserGHPAT" diff --git a/extensions/experiences/configure_aws_network/setup.yml b/extensions/experiences/configure_aws_network/setup.yml index 63974b10..f4bb3083 100644 --- a/extensions/experiences/configure_aws_network/setup.yml +++ b/extensions/experiences/configure_aws_network/setup.yml @@ -19,7 +19,6 @@ controller_projects: scm_delete_on_update: 'no' scm_type: git scm_update_on_launch: 'no' - scm_credential: "{{ scm_credential }}" scm_url: https://github.com/GomathiselviS/cloud.aws_ops.git From cb8ccd3886cc6a6d14ace4eb1fdac216cdff7d12 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Fri, 22 Nov 2024 10:11:55 -0500 Subject: [PATCH 05/17] Fix survey --- .../template_surveys/configure_aws_network.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml b/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml index 0ea327cc..8b7448fa 100644 --- a/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml +++ b/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml @@ -1,9 +1,3 @@ -ec2_networking_resources_vpc_name: "{{ vpc_name }}" - ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" - ec2_networking_resources_subnet_cidr_block: "{{ subnet }}" - ec2_networking_resources_sg_internal_name: "{{ security_group_internal }}" - ec2_networking_resources_sg_internal_description: "{{ security_group_internal_description }}" - --- name: "AWS Network Configuration Survey" description: "Survey to configure aws network Rresources to create an EC2 instance" From ba0594140f786e97aff11623fa4e988f35d32419 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Fri, 22 Nov 2024 10:32:24 -0500 Subject: [PATCH 06/17] Add region --- .../playbooks/run_configure_aws_network.yml | 1 + .../template_surveys/configure_aws_network.yaml | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml b/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml index 5fc463c7..f4fab236 100644 --- a/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml +++ b/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml @@ -36,6 +36,7 @@ ansible.builtin.include_role: name: cloud.aws_ops.ec2_networking_resources vars: + aws_region: "{{ region }}" ec2_networking_resources_vpc_name: "{{ vpc_name }}" ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" ec2_networking_resources_subnet_cidr_block: "{{ subnet }}" diff --git a/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml b/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml index 8b7448fa..89fa9bc0 100644 --- a/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml +++ b/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml @@ -12,6 +12,12 @@ spec: required: true default: "full" + - type: "text" + question_name: "AWS region" + question_description: "The AWS region where the resources should be created." + variable: "region" + required: true + - type: "text" question_name: "VPC name" question_description: "The name of the VPC to create." From b443c35bc95fb78a3844d9a13650578b17a7f5dd Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Fri, 22 Nov 2024 13:29:47 -0500 Subject: [PATCH 07/17] rename yaml file --- .../playbooks/run_configure_aws_network.yml | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml diff --git a/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml b/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml deleted file mode 100644 index f4fab236..00000000 --- a/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yml +++ /dev/null @@ -1,45 +0,0 @@ ---- -- name: Create necessary network resources - hosts: localhost - gather_facts: false - tasks: - - name: Create a list of dictionaries for security group rules - ansible.builtin.set_fact: - sg_internal_rules: >- - {{ - [ - { - 'proto': security_group_1_proto, - 'ports': security_group_1_port, - 'cidr_ip': security_group_1_cidr - }, - { - 'proto': security_group_2_proto, - 'ports': security_group_2_port, - 'cidr_ip': security_group_2_cidr - }, - { - 'proto': security_group_3_proto, - 'ports': security_group_3_port, - 'cidr_ip': security_group_3_cidr - } - ] | selectattr('proto', 'defined') | selectattr('ports', 'defined') | selectattr('cidr_ip', 'defined') | list - }} - - - name: Set default value for the security group rules if nothing is passed. - ansible.builtin.set_fact: - sg_internal_rules: "{{ sg_internal_rules | default([ - {'proto': 'tcp', 'port': '22', 'cidr_ip': vpc_cidr} - ]) }}" - - - name: Configure Network resources - ansible.builtin.include_role: - name: cloud.aws_ops.ec2_networking_resources - vars: - aws_region: "{{ region }}" - ec2_networking_resources_vpc_name: "{{ vpc_name }}" - ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" - ec2_networking_resources_subnet_cidr_block: "{{ subnet }}" - ec2_networking_resources_sg_internal_name: "{{ security_group_internal }}" - ec2_networking_resources_sg_internal_description: "{{ security_group_internal_description }}" - ec2_networking_resources_sg_internal_rules: "{{ sg_internal_rules }}" From 5a3780ae87a8ca7b4ef4adfbbc6bf2b5b4995e25 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Fri, 22 Nov 2024 14:47:31 -0500 Subject: [PATCH 08/17] Fix typo --- .../playbooks/run_configure_aws_network.yaml | 45 +++++++++++++++++++ .../configure_aws_network/setup.yml | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yaml diff --git a/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yaml b/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yaml new file mode 100644 index 00000000..f4fab236 --- /dev/null +++ b/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yaml @@ -0,0 +1,45 @@ +--- +- name: Create necessary network resources + hosts: localhost + gather_facts: false + tasks: + - name: Create a list of dictionaries for security group rules + ansible.builtin.set_fact: + sg_internal_rules: >- + {{ + [ + { + 'proto': security_group_1_proto, + 'ports': security_group_1_port, + 'cidr_ip': security_group_1_cidr + }, + { + 'proto': security_group_2_proto, + 'ports': security_group_2_port, + 'cidr_ip': security_group_2_cidr + }, + { + 'proto': security_group_3_proto, + 'ports': security_group_3_port, + 'cidr_ip': security_group_3_cidr + } + ] | selectattr('proto', 'defined') | selectattr('ports', 'defined') | selectattr('cidr_ip', 'defined') | list + }} + + - name: Set default value for the security group rules if nothing is passed. + ansible.builtin.set_fact: + sg_internal_rules: "{{ sg_internal_rules | default([ + {'proto': 'tcp', 'port': '22', 'cidr_ip': vpc_cidr} + ]) }}" + + - name: Configure Network resources + ansible.builtin.include_role: + name: cloud.aws_ops.ec2_networking_resources + vars: + aws_region: "{{ region }}" + ec2_networking_resources_vpc_name: "{{ vpc_name }}" + ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" + ec2_networking_resources_subnet_cidr_block: "{{ subnet }}" + ec2_networking_resources_sg_internal_name: "{{ security_group_internal }}" + ec2_networking_resources_sg_internal_description: "{{ security_group_internal_description }}" + ec2_networking_resources_sg_internal_rules: "{{ sg_internal_rules }}" diff --git a/extensions/experiences/configure_aws_network/setup.yml b/extensions/experiences/configure_aws_network/setup.yml index f4bb3083..5852414f 100644 --- a/extensions/experiences/configure_aws_network/setup.yml +++ b/extensions/experiences/configure_aws_network/setup.yml @@ -4,7 +4,7 @@ controller_labels: - name: cloud.aws_ops organization: "{{ organization }}" - - name: confgiure_aws_network_experience + - name: configure_aws_network_experience organization: "{{ organization }}" - name: run_configure_aws_network organization: "{{ organization }}" From c30364a88b1f767fd988e1c9aea56655da987469 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Fri, 22 Nov 2024 15:01:48 -0500 Subject: [PATCH 09/17] Add inventory --- extensions/experiences/configure_aws_network/setup.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/experiences/configure_aws_network/setup.yml b/extensions/experiences/configure_aws_network/setup.yml index 5852414f..dbd30042 100644 --- a/extensions/experiences/configure_aws_network/setup.yml +++ b/extensions/experiences/configure_aws_network/setup.yml @@ -26,6 +26,8 @@ controller_projects: # controller_templates: - name: AWS Operations / Configure AWS Network for EC2 + ask_inventory_on_launch: true + ask_execution_environment_on_launch: true description: This job template creates the necessary network infrastructure needed to configure AWS EC2 instance project: AWS Operations / Configure AWS Network Experience Project playbook: extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yaml From cc0763a23230f05427737c4633abca75347fb977 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Fri, 22 Nov 2024 15:29:33 -0500 Subject: [PATCH 10/17] change scm_branch --- extensions/experiences/configure_aws_network/setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/experiences/configure_aws_network/setup.yml b/extensions/experiences/configure_aws_network/setup.yml index dbd30042..fb821c47 100644 --- a/extensions/experiences/configure_aws_network/setup.yml +++ b/extensions/experiences/configure_aws_network/setup.yml @@ -14,7 +14,7 @@ controller_labels: controller_projects: - name: AWS Operations / Configure AWS Network Experience Project organization: "{{ organization }}" - scm_branch: main + scm_branch: experience scm_clean: 'no' scm_delete_on_update: 'no' scm_type: git From c84c17b40c626c9b3cdb9e4a05854f006690a5f7 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 2 Dec 2024 10:54:53 -0500 Subject: [PATCH 11/17] Renamed experiences to patterns --- .../{experiences => patterns}/configure_aws_network/README.md | 0 .../configure_aws_network/group_vars/all.yaml | 0 .../playbooks/run_configure_aws_network.yaml | 0 .../{experiences => patterns}/configure_aws_network/setup.yml | 0 .../template_surveys/configure_aws_network.yaml | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename extensions/{experiences => patterns}/configure_aws_network/README.md (100%) rename extensions/{experiences => patterns}/configure_aws_network/group_vars/all.yaml (100%) rename extensions/{experiences => patterns}/configure_aws_network/playbooks/run_configure_aws_network.yaml (100%) rename extensions/{experiences => patterns}/configure_aws_network/setup.yml (100%) rename extensions/{experiences => patterns}/configure_aws_network/template_surveys/configure_aws_network.yaml (100%) diff --git a/extensions/experiences/configure_aws_network/README.md b/extensions/patterns/configure_aws_network/README.md similarity index 100% rename from extensions/experiences/configure_aws_network/README.md rename to extensions/patterns/configure_aws_network/README.md diff --git a/extensions/experiences/configure_aws_network/group_vars/all.yaml b/extensions/patterns/configure_aws_network/group_vars/all.yaml similarity index 100% rename from extensions/experiences/configure_aws_network/group_vars/all.yaml rename to extensions/patterns/configure_aws_network/group_vars/all.yaml diff --git a/extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yaml b/extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml similarity index 100% rename from extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yaml rename to extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml diff --git a/extensions/experiences/configure_aws_network/setup.yml b/extensions/patterns/configure_aws_network/setup.yml similarity index 100% rename from extensions/experiences/configure_aws_network/setup.yml rename to extensions/patterns/configure_aws_network/setup.yml diff --git a/extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml b/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yaml similarity index 100% rename from extensions/experiences/configure_aws_network/template_surveys/configure_aws_network.yaml rename to extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yaml From a8549fd5651ea4a571fe5545053c0d5a46dae930 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 2 Dec 2024 11:12:51 -0500 Subject: [PATCH 12/17] Replace experience --- .../patterns/configure_aws_network/setup.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/extensions/patterns/configure_aws_network/setup.yml b/extensions/patterns/configure_aws_network/setup.yml index fb821c47..8fde1dff 100644 --- a/extensions/patterns/configure_aws_network/setup.yml +++ b/extensions/patterns/configure_aws_network/setup.yml @@ -4,7 +4,7 @@ controller_labels: - name: cloud.aws_ops organization: "{{ organization }}" - - name: configure_aws_network_experience + - name: configure_aws_network_pattern organization: "{{ organization }}" - name: run_configure_aws_network organization: "{{ organization }}" @@ -12,7 +12,7 @@ controller_labels: # Projects # controller_projects: - - name: AWS Operations / Configure AWS Network Experience Project + - name: AWS Operations / Configure AWS Network Pattern Project organization: "{{ organization }}" scm_branch: experience scm_clean: 'no' @@ -29,14 +29,14 @@ controller_templates: ask_inventory_on_launch: true ask_execution_environment_on_launch: true description: This job template creates the necessary network infrastructure needed to configure AWS EC2 instance - project: AWS Operations / Configure AWS Network Experience Project - playbook: extensions/experiences/configure_aws_network/playbooks/run_configure_aws_network.yaml + project: AWS Operations / Configure AWS Network Pattern Project + playbook: extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml job_type: "run" - organization: "{{ organization | default('Default') }}" + organization: "{{ organization }}" labels: - cloud.aws_ops - - configure_aws_network_experience + - configure_aws_network_pattern - run_configure_aws_network credentials: aws-instance survey_enabled: true - survey_spec: "{{ lookup('file', experience.path.replace('setup.yml', '') + 'template_surveys/configure_aws_network.yaml') | from_yaml }}" + survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/configure_aws_network.yaml') | from_yaml }}" From cdec1b1327d0369911c3427c0b9a61645ab0e3c0 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 2 Dec 2024 12:49:16 -0500 Subject: [PATCH 13/17] Rename file --- extensions/patterns/configure_aws_network/setup.yml | 4 +++- ...gure_aws_network.yaml => configure_aws_network.yml} | 10 ---------- 2 files changed, 3 insertions(+), 11 deletions(-) rename extensions/patterns/configure_aws_network/template_surveys/{configure_aws_network.yaml => configure_aws_network.yml} (93%) diff --git a/extensions/patterns/configure_aws_network/setup.yml b/extensions/patterns/configure_aws_network/setup.yml index 8fde1dff..88ac8069 100644 --- a/extensions/patterns/configure_aws_network/setup.yml +++ b/extensions/patterns/configure_aws_network/setup.yml @@ -28,6 +28,8 @@ controller_templates: - name: AWS Operations / Configure AWS Network for EC2 ask_inventory_on_launch: true ask_execution_environment_on_launch: true + ask_credential_on_launch: true + ask_verbosity_on_launch: true description: This job template creates the necessary network infrastructure needed to configure AWS EC2 instance project: AWS Operations / Configure AWS Network Pattern Project playbook: extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml @@ -39,4 +41,4 @@ controller_templates: - run_configure_aws_network credentials: aws-instance survey_enabled: true - survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/configure_aws_network.yaml') | from_yaml }}" + survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/configure_aws_network.yml') | from_yaml }}" diff --git a/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yaml b/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml similarity index 93% rename from extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yaml rename to extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml index 89fa9bc0..1716f90a 100644 --- a/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yaml +++ b/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml @@ -2,16 +2,6 @@ name: "AWS Network Configuration Survey" description: "Survey to configure aws network Rresources to create an EC2 instance" spec: - - type: "multiplechoice" - question_name: "Backup Type" - question_description: "Select the type of backup" - variable: "backup_type" - choices: - - "full" - - "diff" - required: true - default: "full" - - type: "text" question_name: "AWS region" question_description: "The AWS region where the resources should be created." From 7b9b729b7d464eaff30372013236a5b869a9bb37 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 2 Dec 2024 12:54:36 -0500 Subject: [PATCH 14/17] Fix survey typo --- .../playbooks/run_configure_aws_network.yaml | 2 +- .../template_surveys/configure_aws_network.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml b/extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml index f4fab236..02740675 100644 --- a/extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml +++ b/extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml @@ -40,6 +40,6 @@ ec2_networking_resources_vpc_name: "{{ vpc_name }}" ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr }}" ec2_networking_resources_subnet_cidr_block: "{{ subnet }}" - ec2_networking_resources_sg_internal_name: "{{ security_group_internal }}" + ec2_networking_resources_sg_internal_name: "{{ security_group_internal_name }}" ec2_networking_resources_sg_internal_description: "{{ security_group_internal_description }}" ec2_networking_resources_sg_internal_rules: "{{ sg_internal_rules }}" diff --git a/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml b/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml index 1716f90a..2ca0cf88 100644 --- a/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml +++ b/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml @@ -29,13 +29,13 @@ spec: - type: "text" question_name: "Internal Security Group name" question_description: "The name of the security group to create." - variable: "security_group_internal" + variable: "security_group_internal_name" required: true - type: "text" question_name: "Internal Security Group description" question_description: "The name of the security group to create." - variable: "security_group_internal" + variable: "security_group_internal_description" required: true - type: "text" From 00507da35c31140aff7cf361cfeaa744d6fed52a Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 2 Dec 2024 15:43:19 -0500 Subject: [PATCH 15/17] Fix sg_rules --- .../playbooks/run_configure_aws_network.yaml | 25 +++---------------- .../configure_aws_network.yml | 6 ++--- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml b/extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml index 02740675..c9ff138c 100644 --- a/extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml +++ b/extensions/patterns/configure_aws_network/playbooks/run_configure_aws_network.yaml @@ -3,32 +3,13 @@ hosts: localhost gather_facts: false tasks: - - name: Create a list of dictionaries for security group rules + - name: Get list of internal sg rules ansible.builtin.set_fact: - sg_internal_rules: >- - {{ - [ - { - 'proto': security_group_1_proto, - 'ports': security_group_1_port, - 'cidr_ip': security_group_1_cidr - }, - { - 'proto': security_group_2_proto, - 'ports': security_group_2_port, - 'cidr_ip': security_group_2_cidr - }, - { - 'proto': security_group_3_proto, - 'ports': security_group_3_port, - 'cidr_ip': security_group_3_cidr - } - ] | selectattr('proto', 'defined') | selectattr('ports', 'defined') | selectattr('cidr_ip', 'defined') | list - }} + sg_rules: "{{ security_group_rules | split(';') | list }}" - name: Set default value for the security group rules if nothing is passed. ansible.builtin.set_fact: - sg_internal_rules: "{{ sg_internal_rules | default([ + sg_internal_rules: "{{ sg_rules | default([ {'proto': 'tcp', 'port': '22', 'cidr_ip': vpc_cidr} ]) }}" diff --git a/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml b/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml index 2ca0cf88..7355b51f 100644 --- a/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml +++ b/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml @@ -39,9 +39,9 @@ spec: required: true - type: "text" - question_name: "Internal Security Group rule 1 protocol" - question_description: "The IP protocol name. If not provided, ssh will be used" - variable: "security_group_1_proto" + question_name: "Dict of Internal Security Group rules, seperated by semi colon" + question_description: 'Dictionaries of Security Group Rules. e.g. {"proto": "tcp", "ports": "22", "cidr_ip": "10.1.1.0/16"}; {"proto": "tcp", "ports": "8000-8010", "cidr_ip": "10.1.1.0/16"}' + variable: "security_group_rules" required: false - type: "text" From d7cc9ee69f6341b25f8fdcc7570548402eaecb6a Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 2 Dec 2024 15:44:05 -0500 Subject: [PATCH 16/17] Fix sg_rules --- .../configure_aws_network.yml | 48 ------------------- 1 file changed, 48 deletions(-) diff --git a/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml b/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml index 7355b51f..b9ff430a 100644 --- a/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml +++ b/extensions/patterns/configure_aws_network/template_surveys/configure_aws_network.yml @@ -43,51 +43,3 @@ spec: question_description: 'Dictionaries of Security Group Rules. e.g. {"proto": "tcp", "ports": "22", "cidr_ip": "10.1.1.0/16"}; {"proto": "tcp", "ports": "8000-8010", "cidr_ip": "10.1.1.0/16"}' variable: "security_group_rules" required: false - - - type: "text" - question_name: "Internal Security Group rule 1 port" - question_description: "Port numbers the traffic is going to. Can be a single port, or a range of ports, for example, 8000-8010. If not provided 22 will be used" - variable: "security_group_1_port" - required: false - - - type: "text" - question_name: "Internal Security Group rule 1 cidr block" - question_description: "The CIDR block traffic is coming from. If not provided, cidr block of the vpc created will be used." - variable: "security_group_1_cidr" - required: false - - - type: "text" - question_name: "Internal Security Group rule 2 protocol" - question_description: "The IP protocol name." - variable: "security_group_2_proto" - required: false - - - type: "text" - question_name: "Internal Security Group rule 2 port" - question_description: "Port numbers the traffic is going to. Can be a single port, or a range of ports, for example, 8000-8010." - variable: "security_group_2_port" - required: false - - - type: "text" - question_name: "Internal Security Group rule 2 cidr block" - question_description: "The CIDR block traffic is coming from." - variable: "security_group_2_cidr" - required: false - - - type: "text" - question_name: "Internal Security Group rule 3 protocol" - question_description: "The IP protocol name." - variable: "security_group_3_proto" - required: false - - - type: "text" - question_name: "Internal Security Group rule 3 port" - question_description: "Port numbers the traffic is going to. Can be a single port, or a range of ports, for example, 8000-8010." - variable: "security_group_3_port" - required: false - - - type: "text" - question_name: "Internal Security Group rule 3 cidr block" - question_description: "The CIDR block traffic is coming from." - variable: "security_group_3_cidr" - required: false From bf33386240a4def9888cf4bfa961b251a4016358 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 2 Dec 2024 15:55:32 -0500 Subject: [PATCH 17/17] linters fix --- extensions/patterns/configure_aws_network/setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/patterns/configure_aws_network/setup.yml b/extensions/patterns/configure_aws_network/setup.yml index 88ac8069..55781321 100644 --- a/extensions/patterns/configure_aws_network/setup.yml +++ b/extensions/patterns/configure_aws_network/setup.yml @@ -38,7 +38,7 @@ controller_templates: labels: - cloud.aws_ops - configure_aws_network_pattern - - run_configure_aws_network + - run_configure_aws_network credentials: aws-instance survey_enabled: true survey_spec: "{{ lookup('file', pattern.path.replace('setup.yml', '') + 'template_surveys/configure_aws_network.yml') | from_yaml }}"