diff --git a/db/aws.yml b/db/aws.yml
new file mode 100644
index 0000000..efe31c3
--- /dev/null
+++ b/db/aws.yml
@@ -0,0 +1,57 @@
+- name: Create AWS EC2 instance
+ amazon.aws.ec2_instance:
+ user_data: |
+ #cloud-config
+ system_info:
+ default_user:
+ name: {{ myUsername }}
+ name: '{{ tempName }}'
+ image_id: '{{ amis.images[-1].image_id }}'
+ key_name: '{{ keyName }}'
+ network:
+ assign_public_ip: yes
+ security_groups: '{{ securityGroups }}'
+ region: '{{ awsRegion }}'
+ availability_zone: '{{ availabilityZone }}'
+ # aws_profile: '{{ awsProfile }}'
+ instance_type: '{{ instanceType }}'
+ count: '{{ vmNum | default(1) }}'
+ volumes:
+ - device_name: '{{ deviceName }}'
+ ebs:
+ volume_type: '{{ volumeType }}'
+ volume_size: '{{ volumeSize }}'
+ state: running
+ wait: true
+ register: ec2
+
+- name: Add Host to awsEC2 Group
+ add_host:
+ hostname: '{{ item.public_ip_address }}'
+ ansible_port: 22
+ ansible_user: '{{ myUsername }}'
+ ansible_ssh_private_key_file: '{{ keyLocation }}'
+ groups: awsEC2
+ loop: '{{ ec2.instances }}'
+
+- name: Rename AWS EC2 instance
+ amazon.aws.ec2_tag:
+ # aws_profile: '{{ awsProfile }}'
+ region: '{{ awsRegion }}'
+ resource: '{{ item }}'
+ tags:
+ Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
+ Owner: '{{ semaphore_vars.task_details.username|upper }}'
+ state: present
+ loop: '{{ ec2.instance_ids }}'
+
+- name: SSH Check
+ ansible.builtin.wait_for:
+ host: '{{ item.public_ip_address }}'
+ port: 22
+ timeout: 120
+ loop: '{{ ec2.instances }}'
+
+- name: Wait for 30 seconds AWS Instance
+ ansible.builtin.pause:
+ seconds: 30
\ No newline at end of file
diff --git a/db/fail.yml b/db/fail.yml
new file mode 100644
index 0000000..baa28e2
--- /dev/null
+++ b/db/fail.yml
@@ -0,0 +1,12 @@
+- name: Terminate Failed Instance(s)
+ amazon.aws.ec2_instance:
+ state: absent
+ instance_ids:
+ - '{{ item.instance_id }}'
+ loop: '{{ ec2.instances }}'
+
+- name: Task Failure Notification
+ debug:
+ msg:
+ - "Task Failed!"
+ - "Failed AWS EC2 Instance(s) terminated."
\ No newline at end of file
diff --git a/db/final.yml b/db/final.yml
new file mode 100644
index 0000000..5ec0f7a
--- /dev/null
+++ b/db/final.yml
@@ -0,0 +1,27 @@
+# - name: WebAPI Notification
+# ansible.builtin.uri:
+# url: '{{ webAPI }}'
+# method: POST
+# body_format: json
+# body:
+# username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }} Build Complete"
+# content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }}"
+# avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
+# status_code:
+# - 200
+# - 202
+# - 204
+# loop: '{{ ec2.instances }}'
+# tags: default
+
+- name: Display AWS EC2 Information
+ debug:
+ msg:
+ - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }}"
+ - 'AWS ID - {{ item.instance_id }}'
+ - 'AWS Region - {{ awsRegion }}'
+ - 'Public IP - {{ item.public_ip_address }}'
+ - 'Public DNS - {{ item.public_dns_name }}'
+ - 'Private IP - {{ item.private_ip_address }}'
+ - 'Private DNS - {{ item.private_dns_name }}'
+ loop: '{{ ec2.instances }}'
\ No newline at end of file
diff --git a/db/main.yml b/db/main.yml
index f38e924..ad8a7ef 100644
--- a/db/main.yml
+++ b/db/main.yml
@@ -1,186 +1,107 @@
-- name: AWS Initial Configuration
- hosts: local
- gather_facts: no
- tasks:
- - name: Import initial.yml
- import_tasks: initial.yml
- tags: default
+tasks:
+ block:
+ - name: Task to be failed
+ ansible.builtin.shell: /bin/false
-- name: AWS AMI Info
- hosts: local
- gather_facts: no
- tasks:
- - name: Import ami.yml
- import_tasks: ami.yml
+ - name: AWS Initial Configuration
+ hosts: local
+ gather_facts: no
+ tasks:
+ - name: Import initial.yml
+ import_tasks: initial.yml
+ tags: default
-# - name: SSO 2FA
-# hosts: local
-# gather_facts: no
-# tasks:
-# - name: Import sso.yml
-# import_tasks: sso.yml
-# no_log: True
-# tags: default
+ - name: AWS AMI Info
+ hosts: local
+ gather_facts: no
+ tasks:
+ - name: Import ami.yml
+ import_tasks: ami.yml
-- name: AWS EC2 Management
- hosts: local
- vars:
- tempName: SEM-{{ 2048 | random }}
- gather_facts: no
- tasks:
- - name: Create AWS EC2 instance
- amazon.aws.ec2_instance:
- user_data: |
- #cloud-config
- system_info:
- default_user:
- name: {{ myUsername }}
- name: '{{ tempName }}'
- image_id: '{{ amis.images[-1].image_id }}'
- key_name: '{{ keyName }}'
- network:
- assign_public_ip: yes
- security_groups: '{{ securityGroups }}'
- region: '{{ awsRegion }}'
- availability_zone: '{{ availabilityZone }}'
- # aws_profile: '{{ awsProfile }}'
- instance_type: '{{ instanceType }}'
- count: '{{ vmNum | default(1) }}'
- volumes:
- - device_name: '{{ deviceName }}'
- ebs:
- volume_type: '{{ volumeType }}'
- volume_size: '{{ volumeSize }}'
- state: running
- wait: true
- register: ec2
- no_log: true
- tags: default
+ # - name: SSO 2FA
+ # hosts: local
+ # gather_facts: no
+ # tasks:
+ # - name: Import sso.yml
+ # import_tasks: sso.yml
+ # no_log: True
+ # tags: default
- - name: Add Host to awsEC2 Group
- add_host:
- hostname: '{{ item.public_ip_address }}'
- ansible_port: 22
- ansible_user: '{{ myUsername }}'
- ansible_ssh_private_key_file: '{{ keyLocation }}'
- groups: awsEC2
- loop: '{{ ec2.instances }}'
- tags: default
-
- - name: Rename AWS EC2 instance
- amazon.aws.ec2_tag:
- # aws_profile: '{{ awsProfile }}'
- region: '{{ awsRegion }}'
- resource: '{{ item }}'
- tags:
- Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
- Owner: '{{ semaphore_vars.task_details.username|upper }}'
- state: present
- loop: '{{ ec2.instance_ids }}'
- tags: default
+ - name: AWS EC2 Management
+ hosts: local
+ vars:
+ tempName: SEM-{{ 2048 | random }}
+ gather_facts: no
+ tasks:
+ - name: Import aws.yml
+ import_tasks: aws.yml
+ tags: default
- - name: SSH Check
- ansible.builtin.wait_for:
- host: '{{ item.public_ip_address }}'
- port: 22
- timeout: 120
- loop: '{{ ec2.instances }}'
- tags: default
+ - name: Modify OS Config
+ hosts: awsEC2
+ gather_facts: no
+ become: yes
+ tasks:
+ - name: Import system.yml
+ import_tasks: system.yml
+ tags: default
-- name: Wait for AWS Instance
- hosts: local
- gather_facts: no
- tasks:
- - name: Pause for 30 seconds
- ansible.builtin.pause:
- seconds: 30
- tags: default
+ - name: Reboot EC2 Instance
+ hosts: awsEC2
+ gather_facts: no
+ become: yes
+ tasks:
+ - name: Reboot
+ reboot:
+ tags: default
-- name: Modify OS Config
- hosts: awsEC2
- gather_facts: no
- become: yes
- tasks:
- - name: Import system.yml
- import_tasks: system.yml
- tags: default
+ - name: Manage Users
+ hosts: awsEC2
+ gather_facts: no
+ become: yes
+ tasks:
+ - name: Import users.yml
+ import_tasks: users.yml
+ no_log: True
+ tags: default
-- name: Reboot EC2 Instance
- hosts: awsEC2
- gather_facts: no
- become: yes
- tasks:
- - name: Reboot
- reboot:
- tags: default
+ - name: Install Software
+ hosts: awsEC2
+ gather_facts: yes
+ become: yes
+ tasks:
+ - name: Import software.yml
+ import_tasks: software.yml
+ tags: default
-- name: Manage Users
- hosts: awsEC2
- gather_facts: no
- become: yes
- tasks:
- - name: Import users.yml
- import_tasks: users.yml
- no_log: True
- tags: default
+ - name: Create Podman Containers
+ hosts: awsEC2
+ gather_facts: no
+ tasks:
+ - name: Import podman.yml
+ import_tasks: podman.yml
-- name: Install Software
- hosts: awsEC2
- gather_facts: yes
- become: yes
- tasks:
- - name: Import software.yml
- import_tasks: software.yml
- tags: default
+ - name: Add CRON Jobs
+ hosts: awsEC2
+ gather_facts: no
+ become: yes
+ tasks:
+ - name: Import cron.yml
+ import_tasks: cron.yml
+ tags: default
-- name: Create Podman Containers
- hosts: awsEC2
- gather_facts: no
- tasks:
- - name: Import podman.yml
- import_tasks: podman.yml
+ - name: Final tasks
+ hosts: local
+ gather_facts: no
+ tasks:
+ - name: Import final.yml
+ import_tasks: final.yml
+ tags: default
-- name: Add CRON Jobs
- hosts: awsEC2
- gather_facts: no
- become: yes
- tasks:
- - name: Import cron.yml
- import_tasks: cron.yml
- tags: default
-
-- name: AWS EC2 Instance Created and Setup
- hosts: local
- gather_facts: no
- tasks:
- # - name: WebAPI Notification
- # ansible.builtin.uri:
- # url: '{{ webAPI }}'
- # method: POST
- # body_format: json
- # body:
- # username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].DBSHORT }} Build Complete"
- # content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }} \nDB Name - {{ hostvars[item.public_ip_address].DBNAME }} \nDB User - {{ hostvars[item.public_ip_address].DBUSER }} \nDB Port - {{ hostvars[item.public_ip_address].DBPORT }}"
- # avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
- # status_code:
- # - 200
- # - 202
- # - 204
- # loop: '{{ ec2.instances }}'
- # tags: default
-
- - name: Display AWS EC2 Information
- debug:
- msg:
- - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].DBSHORT }}"
- - 'AWS ID - {{ item.instance_id }}'
- - 'AWS Region - {{ awsRegion }}'
- - 'Public IP - {{ item.public_ip_address }}'
- - 'Public DNS - {{ item.public_dns_name }}'
- - 'Private IP - {{ item.private_ip_address }}'
- - 'Private DNS - {{ item.private_dns_name }}'
- - "DB Name - {{ hostvars[item.public_ip_address].DBNAME }}"
- - "DB User - {{ hostvars[item.public_ip_address].DBUSER }}"
- - "DB Port - {{ hostvars[item.public_ip_address].DBPORT }}"
- loop: '{{ ec2.instances }}'
- tags: default
\ No newline at end of file
+ rescue:
+ - name: Task Failure
+ hosts: local
+ gather_facts: no
+ tasks:
+ - name: Import fail.yml
+ import_tasks: fail.yml
\ No newline at end of file
diff --git a/rhel/aws.yml b/rhel/aws.yml
new file mode 100644
index 0000000..f64c7cc
--- /dev/null
+++ b/rhel/aws.yml
@@ -0,0 +1,58 @@
+- name: Create AWS EC2 instance
+ amazon.aws.ec2_instance:
+ user_data: |
+ #cloud-config
+ system_info:
+ default_user:
+ name: {{ myUsername }}
+ name: '{{ tempName }}'
+ image_id: '{{ amis.images[-1].image_id }}'
+ key_name: '{{ keyName }}'
+ network:
+ assign_public_ip: yes
+ security_groups: '{{ securityGroups }}'
+ region: '{{ awsRegion }}'
+ availability_zone: '{{ availabilityZone }}'
+ # aws_profile: '{{ awsProfile }}'
+ instance_type: '{{ instanceType }}'
+ count: '{{ vmNum | default(1) }}'
+ volumes:
+ - device_name: '{{ deviceName }}'
+ ebs:
+ volume_type: '{{ volumeType }}'
+ volume_size: '{{ volumeSize }}'
+ state: running
+ wait: true
+ register: ec2
+
+- name: Add Host to awsEC2 Group
+ add_host:
+ hostname: '{{ item.public_ip_address }}'
+ ansible_port: 22
+ ansible_user: '{{ myUsername }}'
+ ansible_ssh_private_key_file: '{{ keyLocation }}'
+ groups: awsEC2
+ loop: '{{ ec2.instances }}'
+
+- name: Rename AWS EC2 instance
+ amazon.aws.ec2_tag:
+ # aws_profile: '{{ awsProfile }}'
+ region: '{{ awsRegion }}'
+ resource: '{{ item }}'
+ tags:
+ Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
+ Owner: '{{ semaphore_vars.task_details.username|upper }}'
+ OS: '{{ imageName }}'
+ state: present
+ loop: '{{ ec2.instance_ids }}'
+
+- name: SSH Check
+ ansible.builtin.wait_for:
+ host: '{{ item.public_ip_address }}'
+ port: 22
+ timeout: 120
+ loop: '{{ ec2.instances }}'
+
+- name: Wait for 30 seconds AWS Instance
+ ansible.builtin.pause:
+ seconds: 30
\ No newline at end of file
diff --git a/rhel/fail.yml b/rhel/fail.yml
new file mode 100644
index 0000000..6398502
--- /dev/null
+++ b/rhel/fail.yml
@@ -0,0 +1,12 @@
+- name: Terminate Failed Instance(s)
+ amazon.aws.ec2_instance:
+ state: absent
+ instance_ids:
+ - '{{ item.instance_id }}'
+ loop: '{{ ec2.instances }}'
+
+- name: Task Fail Notification
+ debug:
+ msg:
+ - "Task {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} Failed!"
+ - "Failed AWS EC2 Instances have been removed."
\ No newline at end of file
diff --git a/rhel/final.yml b/rhel/final.yml
new file mode 100644
index 0000000..55279ae
--- /dev/null
+++ b/rhel/final.yml
@@ -0,0 +1,30 @@
+- name: Reboot EC2 Instance
+ reboot:
+
+# - name: WebAPI Notification
+# ansible.builtin.uri:
+# url: '{{ webAPI }}'
+# method: POST
+# body_format: json
+# body:
+# username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }} Build Complete"
+# content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }}"
+# avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
+# status_code:
+# - 200
+# - 202
+# - 204
+# loop: '{{ ec2.instances }}'
+# tags: default
+
+- name: Display AWS EC2 Information
+ debug:
+ msg:
+ - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }}"
+ - 'AWS ID - {{ item.instance_id }}'
+ - 'AWS Region - {{ awsRegion }}'
+ - 'Public IP - {{ item.public_ip_address }}'
+ - 'Public DNS - {{ item.public_dns_name }}'
+ - 'Private IP - {{ item.private_ip_address }}'
+ - 'Private DNS - {{ item.private_dns_name }}'
+ loop: '{{ ec2.instances }}'
\ No newline at end of file
diff --git a/rhel/main.yml b/rhel/main.yml
index 61fafa1..161dc46 100644
--- a/rhel/main.yml
+++ b/rhel/main.yml
@@ -28,73 +28,8 @@
tempName: SEM-{{ 2048 | random }}
gather_facts: no
tasks:
- - name: Create AWS EC2 instance
- amazon.aws.ec2_instance:
- user_data: |
- #cloud-config
- system_info:
- default_user:
- name: {{ myUsername }}
- name: '{{ tempName }}'
- image_id: '{{ amis.images[-1].image_id }}'
- key_name: '{{ keyName }}'
- network:
- assign_public_ip: yes
- security_groups: '{{ securityGroups }}'
- region: '{{ awsRegion }}'
- availability_zone: '{{ availabilityZone }}'
- # aws_profile: '{{ awsProfile }}'
- instance_type: '{{ instanceType }}'
- count: '{{ vmNum | default(1) }}'
- volumes:
- - device_name: '{{ deviceName }}'
- ebs:
- volume_type: '{{ volumeType }}'
- volume_size: '{{ volumeSize }}'
- state: running
- wait: true
- register: ec2
- no_log: true
- tags: default
-
- - name: Add Host to awsEC2 Group
- add_host:
- hostname: '{{ item.public_ip_address }}'
- ansible_port: 22
- ansible_user: '{{ myUsername }}'
- ansible_ssh_private_key_file: '{{ keyLocation }}'
- groups: awsEC2
- loop: '{{ ec2.instances }}'
- tags: default
-
- - name: Rename AWS EC2 instance
- amazon.aws.ec2_tag:
- # aws_profile: '{{ awsProfile }}'
- region: '{{ awsRegion }}'
- resource: '{{ item }}'
- tags:
- Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
- Owner: '{{ semaphore_vars.task_details.username|upper }}'
- OS: '{{ imageName }}'
- state: present
- loop: '{{ ec2.instance_ids }}'
- tags: default
-
- - name: SSH Check
- ansible.builtin.wait_for:
- host: '{{ item.public_ip_address }}'
- port: 22
- timeout: 120
- loop: '{{ ec2.instances }}'
- tags: default
-
-- name: Wait for AWS Instance
- hosts: local
- gather_facts: no
- tasks:
- - name: Pause for 30 seconds
- ansible.builtin.pause:
- seconds: 30
+ - name: Import aws.yml
+ import_tasks: aws.yml
tags: default
- name: Modify OS Config
@@ -250,44 +185,10 @@
import_tasks: cron.yml
tags: default
-- name: Reboot EC2 Instance
- hosts: awsEC2
- gather_facts: no
- become: yes
- tasks:
- - name: Reboot
- reboot:
- tags: default
-
-- name: AWS EC2 Instance Created and Setup
+- name: Final tasks
hosts: local
gather_facts: no
- tasks:
- # - name: WebAPI Notification
- # ansible.builtin.uri:
- # url: '{{ webAPI }}'
- # method: POST
- # body_format: json
- # body:
- # username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }} Build Complete"
- # content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }}"
- # avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
- # status_code:
- # - 200
- # - 202
- # - 204
- # loop: '{{ ec2.instances }}'
- # tags: default
-
- - name: Display AWS EC2 Information
- debug:
- msg:
- - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }}"
- - 'AWS ID - {{ item.instance_id }}'
- - 'AWS Region - {{ awsRegion }}'
- - 'Public IP - {{ item.public_ip_address }}'
- - 'Public DNS - {{ item.public_dns_name }}'
- - 'Private IP - {{ item.private_ip_address }}'
- - 'Private DNS - {{ item.private_dns_name }}'
- loop: '{{ ec2.instances }}'
- tags: default
\ No newline at end of file
+ tasks:
+ - name: Import final.yml
+ import_tasks: final.yml
+ tags: default
\ No newline at end of file
diff --git a/sles/aws.yml b/sles/aws.yml
new file mode 100644
index 0000000..f7e15a9
--- /dev/null
+++ b/sles/aws.yml
@@ -0,0 +1,60 @@
+- name: Create AWS EC2 instance
+ amazon.aws.ec2_instance:
+ user_data: |
+ #cloud-config
+ system_info:
+ default_user:
+ name: {{ myUsername }}
+ primary_group: wheel
+ groups: users
+ name: '{{ tempName }}'
+ image_id: '{{ amis.images[-1].image_id }}'
+ key_name: '{{ keyName }}'
+ network:
+ assign_public_ip: yes
+ security_groups: '{{ securityGroups }}'
+ region: '{{ awsRegion }}'
+ availability_zone: '{{ availabilityZone }}'
+ # aws_profile: '{{ awsProfile }}'
+ instance_type: '{{ instanceType }}'
+ count: '{{ vmNum | default(1) }}'
+ volumes:
+ - device_name: '{{ deviceName }}'
+ ebs:
+ volume_type: '{{ volumeType }}'
+ volume_size: '{{ volumeSize }}'
+ state: running
+ wait: true
+ register: ec2
+
+- name: Add Host to awsEC2 Group
+ add_host:
+ hostname: '{{ item.public_ip_address }}'
+ ansible_port: 22
+ ansible_user: '{{ myUsername }}'
+ ansible_ssh_private_key_file: '{{ keyLocation }}'
+ groups: awsEC2
+ loop: '{{ ec2.instances }}'
+
+- name: Rename AWS EC2 instance
+ amazon.aws.ec2_tag:
+ # aws_profile: '{{ awsProfile }}'
+ region: '{{ awsRegion }}'
+ resource: '{{ item }}'
+ tags:
+ Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
+ Owner: '{{ semaphore_vars.task_details.username|upper }}'
+ OS: '{{ imageName }}'
+ state: present
+ loop: '{{ ec2.instance_ids }}'
+
+- name: SSH Check
+ ansible.builtin.wait_for:
+ host: '{{ item.public_ip_address }}'
+ port: 22
+ timeout: 120
+ loop: '{{ ec2.instances }}'
+
+- name: Wait for 30 seconds AWS Instance
+ ansible.builtin.pause:
+ seconds: 30
\ No newline at end of file
diff --git a/sles/final.yml b/sles/final.yml
new file mode 100644
index 0000000..55279ae
--- /dev/null
+++ b/sles/final.yml
@@ -0,0 +1,30 @@
+- name: Reboot EC2 Instance
+ reboot:
+
+# - name: WebAPI Notification
+# ansible.builtin.uri:
+# url: '{{ webAPI }}'
+# method: POST
+# body_format: json
+# body:
+# username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }} Build Complete"
+# content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }}"
+# avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
+# status_code:
+# - 200
+# - 202
+# - 204
+# loop: '{{ ec2.instances }}'
+# tags: default
+
+- name: Display AWS EC2 Information
+ debug:
+ msg:
+ - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }}"
+ - 'AWS ID - {{ item.instance_id }}'
+ - 'AWS Region - {{ awsRegion }}'
+ - 'Public IP - {{ item.public_ip_address }}'
+ - 'Public DNS - {{ item.public_dns_name }}'
+ - 'Private IP - {{ item.private_ip_address }}'
+ - 'Private DNS - {{ item.private_dns_name }}'
+ loop: '{{ ec2.instances }}'
\ No newline at end of file
diff --git a/sles/main.yml b/sles/main.yml
index b032e9b..4ae00ae 100644
--- a/sles/main.yml
+++ b/sles/main.yml
@@ -28,75 +28,8 @@
tempName: SEM-{{ 2048 | random }}
gather_facts: no
tasks:
- - name: Create AWS EC2 instance
- amazon.aws.ec2_instance:
- user_data: |
- #cloud-config
- system_info:
- default_user:
- name: {{ myUsername }}
- primary_group: wheel
- groups: users
- name: '{{ tempName }}'
- image_id: '{{ amis.images[-1].image_id }}'
- key_name: '{{ keyName }}'
- network:
- assign_public_ip: yes
- security_groups: '{{ securityGroups }}'
- region: '{{ awsRegion }}'
- availability_zone: '{{ availabilityZone }}'
- # aws_profile: '{{ awsProfile }}'
- instance_type: '{{ instanceType }}'
- count: '{{ vmNum | default(1) }}'
- volumes:
- - device_name: '{{ deviceName }}'
- ebs:
- volume_type: '{{ volumeType }}'
- volume_size: '{{ volumeSize }}'
- state: running
- wait: true
- register: ec2
- no_log: True
- tags: default
-
- - name: Add Host to awsEC2 Group
- add_host:
- hostname: '{{ item.public_ip_address }}'
- ansible_port: 22
- ansible_user: '{{ myUsername }}'
- ansible_ssh_private_key_file: '{{ keyLocation }}'
- groups: awsEC2
- loop: '{{ ec2.instances }}'
- tags: default
-
- - name: Rename AWS EC2 instance
- amazon.aws.ec2_tag:
- # aws_profile: '{{ awsProfile }}'
- region: '{{ awsRegion }}'
- resource: '{{ item }}'
- tags:
- Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
- Owner: '{{ semaphore_vars.task_details.username|upper }}'
- OS: '{{ imageName }}'
- state: present
- loop: '{{ ec2.instance_ids }}'
- tags: default
-
- - name: SSH Check
- ansible.builtin.wait_for:
- host: '{{ item.public_ip_address }}'
- port: 22
- timeout: 120
- loop: '{{ ec2.instances }}'
- tags: default
-
-- name: Wait for AWS Instance
- hosts: local
- gather_facts: no
- tasks:
- - name: Pause for 30 seconds
- ansible.builtin.pause:
- seconds: 30
+ - name: Import aws.yml
+ import_tasks: aws.yml
tags: default
- name: Modify OS Config
@@ -238,44 +171,10 @@
import_tasks: cron.yml
tags: default
-- name: Reboot EC2 Instance
- hosts: awsEC2
- gather_facts: no
- become: yes
- tasks:
- - name: Reboot
- reboot:
- tags: default
-
-- name: AWS EC2 Instance Created and Setup
+- name: Final tasks
hosts: local
gather_facts: no
- tasks:
- # - name: WebAPI Notification
- # ansible.builtin.uri:
- # url: '{{ webAPI }}'
- # method: POST
- # body_format: json
- # body:
- # username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }} Build Complete"
- # content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }}"
- # avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
- # status_code:
- # - 200
- # - 202
- # - 204
- # loop: '{{ ec2.instances }}'
- # tags: default
-
- - name: Display AWS EC2 Information
- debug:
- msg:
- - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }}"
- - 'AWS ID - {{ item.instance_id }}'
- - 'AWS Region - {{ awsRegion }}'
- - 'Public IP - {{ item.public_ip_address }}'
- - 'Public DNS - {{ item.public_dns_name }}'
- - 'Private IP - {{ item.private_ip_address }}'
- - 'Private DNS - {{ item.private_dns_name }}'
- loop: '{{ ec2.instances }}'
- tags: default
\ No newline at end of file
+ tasks:
+ - name: Import final.yml
+ import_tasks: final.yml
+ tags: default
\ No newline at end of file
diff --git a/ubuntu/aws.yml b/ubuntu/aws.yml
new file mode 100644
index 0000000..f64c7cc
--- /dev/null
+++ b/ubuntu/aws.yml
@@ -0,0 +1,58 @@
+- name: Create AWS EC2 instance
+ amazon.aws.ec2_instance:
+ user_data: |
+ #cloud-config
+ system_info:
+ default_user:
+ name: {{ myUsername }}
+ name: '{{ tempName }}'
+ image_id: '{{ amis.images[-1].image_id }}'
+ key_name: '{{ keyName }}'
+ network:
+ assign_public_ip: yes
+ security_groups: '{{ securityGroups }}'
+ region: '{{ awsRegion }}'
+ availability_zone: '{{ availabilityZone }}'
+ # aws_profile: '{{ awsProfile }}'
+ instance_type: '{{ instanceType }}'
+ count: '{{ vmNum | default(1) }}'
+ volumes:
+ - device_name: '{{ deviceName }}'
+ ebs:
+ volume_type: '{{ volumeType }}'
+ volume_size: '{{ volumeSize }}'
+ state: running
+ wait: true
+ register: ec2
+
+- name: Add Host to awsEC2 Group
+ add_host:
+ hostname: '{{ item.public_ip_address }}'
+ ansible_port: 22
+ ansible_user: '{{ myUsername }}'
+ ansible_ssh_private_key_file: '{{ keyLocation }}'
+ groups: awsEC2
+ loop: '{{ ec2.instances }}'
+
+- name: Rename AWS EC2 instance
+ amazon.aws.ec2_tag:
+ # aws_profile: '{{ awsProfile }}'
+ region: '{{ awsRegion }}'
+ resource: '{{ item }}'
+ tags:
+ Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
+ Owner: '{{ semaphore_vars.task_details.username|upper }}'
+ OS: '{{ imageName }}'
+ state: present
+ loop: '{{ ec2.instance_ids }}'
+
+- name: SSH Check
+ ansible.builtin.wait_for:
+ host: '{{ item.public_ip_address }}'
+ port: 22
+ timeout: 120
+ loop: '{{ ec2.instances }}'
+
+- name: Wait for 30 seconds AWS Instance
+ ansible.builtin.pause:
+ seconds: 30
\ No newline at end of file
diff --git a/ubuntu/final.yml b/ubuntu/final.yml
new file mode 100644
index 0000000..55279ae
--- /dev/null
+++ b/ubuntu/final.yml
@@ -0,0 +1,30 @@
+- name: Reboot EC2 Instance
+ reboot:
+
+# - name: WebAPI Notification
+# ansible.builtin.uri:
+# url: '{{ webAPI }}'
+# method: POST
+# body_format: json
+# body:
+# username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }} Build Complete"
+# content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }}"
+# avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
+# status_code:
+# - 200
+# - 202
+# - 204
+# loop: '{{ ec2.instances }}'
+# tags: default
+
+- name: Display AWS EC2 Information
+ debug:
+ msg:
+ - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }}"
+ - 'AWS ID - {{ item.instance_id }}'
+ - 'AWS Region - {{ awsRegion }}'
+ - 'Public IP - {{ item.public_ip_address }}'
+ - 'Public DNS - {{ item.public_dns_name }}'
+ - 'Private IP - {{ item.private_ip_address }}'
+ - 'Private DNS - {{ item.private_dns_name }}'
+ loop: '{{ ec2.instances }}'
\ No newline at end of file
diff --git a/ubuntu/main.yml b/ubuntu/main.yml
index ff46ebc..9ce0b06 100644
--- a/ubuntu/main.yml
+++ b/ubuntu/main.yml
@@ -28,73 +28,8 @@
tempName: SEM-{{ 2048 | random }}
gather_facts: no
tasks:
- - name: Create AWS EC2 instance
- amazon.aws.ec2_instance:
- user_data: |
- #cloud-config
- system_info:
- default_user:
- name: {{ myUsername }}
- name: '{{ tempName }}'
- image_id: '{{ amis.images[-1].image_id }}'
- key_name: '{{ keyName }}'
- network:
- assign_public_ip: yes
- security_groups: '{{ securityGroups }}'
- region: '{{ awsRegion }}'
- availability_zone: '{{ availabilityZone }}'
- # aws_profile: '{{ awsProfile }}'
- instance_type: '{{ instanceType }}'
- count: '{{ vmNum | default(1) }}'
- volumes:
- - device_name: '{{ deviceName }}'
- ebs:
- volume_type: '{{ volumeType }}'
- volume_size: '{{ volumeSize }}'
- state: running
- wait: true
- register: ec2
- no_log: True
- tags: default
-
- - name: Add Host to awsEC2 Group
- add_host:
- hostname: '{{ item.public_ip_address }}'
- ansible_port: 22
- ansible_user: '{{ myUsername }}'
- ansible_ssh_private_key_file: '{{ keyLocation }}'
- groups: awsEC2
- loop: '{{ ec2.instances }}'
- tags: default
-
- - name: Rename AWS EC2 instance
- amazon.aws.ec2_tag:
- # aws_profile: '{{ awsProfile }}'
- region: '{{ awsRegion }}'
- resource: '{{ item }}'
- tags:
- Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
- Owner: '{{ semaphore_vars.task_details.username|upper }}'
- OS: '{{ imageName }}'
- state: present
- loop: '{{ ec2.instance_ids }}'
- tags: default
-
- - name: SSH Check
- ansible.builtin.wait_for:
- host: '{{ item.public_ip_address }}'
- port: 22
- timeout: 120
- loop: '{{ ec2.instances }}'
- tags: default
-
-- name: Wait for AWS Instance
- hosts: local
- gather_facts: no
- tasks:
- - name: Pause for 30 seconds
- ansible.builtin.pause:
- seconds: 30
+ - name: Import aws.yml
+ import_tasks: aws.yml
tags: default
- name: Modify OS Config
@@ -222,44 +157,10 @@
import_tasks: cron.yml
tags: default
-- name: Reboot EC2 Instance
- hosts: awsEC2
- gather_facts: no
- become: yes
- tasks:
- - name: Reboot
- reboot:
- tags: default
-
-- name: AWS EC2 Instance Created and Setup
+- name: Final tasks
hosts: local
gather_facts: no
- tasks:
- # - name: WebAPI Notification
- # ansible.builtin.uri:
- # url: '{{ webAPI }}'
- # method: POST
- # body_format: json
- # body:
- # username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }} Build Complete"
- # content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }}"
- # avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
- # status_code:
- # - 200
- # - 202
- # - 204
- # loop: '{{ ec2.instances }}'
- # tags: default
-
- - name: Display AWS EC2 Information
- debug:
- msg:
- - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }}"
- - 'AWS ID - {{ item.instance_id }}'
- - 'AWS Region - {{ awsRegion }}'
- - 'Public IP - {{ item.public_ip_address }}'
- - 'Public DNS - {{ item.public_dns_name }}'
- - 'Private IP - {{ item.private_ip_address }}'
- - 'Private DNS - {{ item.private_dns_name }}'
- loop: '{{ ec2.instances }}'
- tags: default
\ No newline at end of file
+ tasks:
+ - name: Import final.yml
+ import_tasks: final.yml
+ tags: default
\ No newline at end of file
diff --git a/win/aws.yml b/win/aws.yml
new file mode 100644
index 0000000..a0d7931
--- /dev/null
+++ b/win/aws.yml
@@ -0,0 +1,67 @@
+- name: Create AWS EC2 instance
+ amazon.aws.ec2_instance:
+ user_data: |
+
+ net user administrator {{ myPassword }}
+ $url = "https://raw.githubusercontent.com/UNiXMIT/UNiXIaC/main/win/ConfigureRemotingForAnsible.ps1"
+ $file = "$env:temp\ConfigureRemotingForAnsible.ps1"
+ Invoke-Webrequest $url -OutFile $file
+ sleep 2
+ powershell.exe -ExecutionPolicy ByPass -File $file -EnableCredSSP -DisableBasicAuth
+
+ name: '{{ tempName }}'
+ image_id: '{{ amis.images[-1].image_id }}'
+ key_name: '{{ keyName }}'
+ network:
+ assign_public_ip: yes
+ security_groups: '{{ securityGroups }}'
+ region: '{{ awsRegion }}'
+ availability_zone: '{{ availabilityZone }}'
+ instance_type: '{{ instanceType }}'
+ count: '{{ vmNum | default(1) }}'
+ volumes:
+ - device_name: '{{ deviceName }}'
+ ebs:
+ volume_type: '{{ volumeType }}'
+ volume_size: '{{ volumeSize }}'
+ # aws_profile: '{{ awsProfile }}'
+ state: running
+ wait: true
+ register: ec2
+
+- name: Add Host to awsEC2 Group
+ add_host:
+ hostname: '{{ item.public_ip_address }}'
+ ansible_user: '{{ ansibleUser }}'
+ ansible_password: '{{ myPassword }}'
+ ansible_connection: winrm
+ ansible_winrm_transport: credssp
+ ansible_winrm_server_cert_validation: ignore
+ ansible_port: 5986
+ ansible_winrm_connection_timeout: 120
+ groups: awsEC2
+ loop: '{{ ec2.instances }}'
+ no_log: True
+
+- name: Rename AWS EC2 instance
+ amazon.aws.ec2_tag:
+ # aws_profile: '{{ awsProfile }}'
+ region: '{{ awsRegion }}'
+ resource: '{{ item }}'
+ tags:
+ Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
+ Owner: '{{ semaphore_vars.task_details.username|upper }}'
+ OS: '{{ imageName }}'
+ state: present
+ loop: '{{ ec2.instance_ids }}'
+
+- name: WinRM Check
+ ansible.builtin.wait_for:
+ host: '{{ item.public_ip_address }}'
+ port: 5986
+ timeout: 300
+ loop: '{{ ec2.instances }}'
+
+- name: Wait for 30 seconds AWS Instance
+ ansible.builtin.pause:
+ seconds: 30
\ No newline at end of file
diff --git a/win/final.yml b/win/final.yml
new file mode 100644
index 0000000..a5a22e0
--- /dev/null
+++ b/win/final.yml
@@ -0,0 +1,30 @@
+- name: Reboot EC2 Instance
+ win_reboot:
+
+# - name: WebAPI Notification
+# ansible.builtin.uri:
+# url: '{{ webAPI }}'
+# method: POST
+# body_format: json
+# body:
+# username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }} Build Complete"
+# content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }}"
+# avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
+# status_code:
+# - 200
+# - 202
+# - 204
+# loop: '{{ ec2.instances }}'
+# tags: default
+
+- name: Display AWS EC2 Information
+ debug:
+ msg:
+ - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }}"
+ - 'AWS ID - {{ item.instance_id }}'
+ - 'AWS Region - {{ awsRegion }}'
+ - 'Public IP - {{ item.public_ip_address }}'
+ - 'Public DNS - {{ item.public_dns_name }}'
+ - 'Private IP - {{ item.private_ip_address }}'
+ - 'Private DNS - {{ item.private_dns_name }}'
+ loop: '{{ ec2.instances }}'
\ No newline at end of file
diff --git a/win/main.yml b/win/main.yml
index aab5e24..6a04981 100644
--- a/win/main.yml
+++ b/win/main.yml
@@ -28,81 +28,8 @@
tempName: SEM-{{ 2048 | random }}
gather_facts: no
tasks:
- - name: Create AWS EC2 instance
- amazon.aws.ec2_instance:
- user_data: |
-
- net user administrator {{ myPassword }}
- $url = "https://raw.githubusercontent.com/UNiXMIT/UNiXIaC/main/win/ConfigureRemotingForAnsible.ps1"
- $file = "$env:temp\ConfigureRemotingForAnsible.ps1"
- Invoke-Webrequest $url -OutFile $file
- sleep 2
- powershell.exe -ExecutionPolicy ByPass -File $file -EnableCredSSP -DisableBasicAuth
-
- name: '{{ tempName }}'
- image_id: '{{ amis.images[-1].image_id }}'
- key_name: '{{ keyName }}'
- network:
- assign_public_ip: yes
- security_groups: '{{ securityGroups }}'
- region: '{{ awsRegion }}'
- availability_zone: '{{ availabilityZone }}'
- instance_type: '{{ instanceType }}'
- count: '{{ vmNum | default(1) }}'
- volumes:
- - device_name: '{{ deviceName }}'
- ebs:
- volume_type: '{{ volumeType }}'
- volume_size: '{{ volumeSize }}'
- # aws_profile: '{{ awsProfile }}'
- state: running
- wait: true
- register: ec2
- tags: default
-
- - name: Add Host to awsEC2 Group
- add_host:
- hostname: '{{ item.public_ip_address }}'
- ansible_user: '{{ ansibleUser }}'
- ansible_password: '{{ myPassword }}'
- ansible_connection: winrm
- ansible_winrm_transport: credssp
- ansible_winrm_server_cert_validation: ignore
- ansible_port: 5986
- ansible_winrm_connection_timeout: 120
- groups: awsEC2
- loop: '{{ ec2.instances }}'
- no_log: True
- tags: default
-
- - name: Rename AWS EC2 instance
- amazon.aws.ec2_tag:
- # aws_profile: '{{ awsProfile }}'
- region: '{{ awsRegion }}'
- resource: '{{ item }}'
- tags:
- Name: '{{ semaphore_vars.task_details.username|upper }}-{{ imageName }}'
- Owner: '{{ semaphore_vars.task_details.username|upper }}'
- OS: '{{ imageName }}'
- state: present
- loop: '{{ ec2.instance_ids }}'
- tags: default
-
- - name: WinRM Check
- ansible.builtin.wait_for:
- host: '{{ item.public_ip_address }}'
- port: 5986
- timeout: 300
- loop: '{{ ec2.instances }}'
- tags: default
-
-- name: Wait for AWS Instance
- hosts: local
- gather_facts: no
- tasks:
- - name: Pause for 30 seconds
- ansible.builtin.pause:
- seconds: 30
+ - name: Import aws.yml
+ import_tasks: aws.yml
tags: default
- name: Optimise Ansible on Windows
@@ -335,43 +262,10 @@
import_tasks: extend.yml
tags: extend
-- name: Reboot EC2 Instance
- hosts: awsEC2
- gather_facts: no
- tasks:
- - name: Reboot
- win_reboot:
- tags: default
-
-- name: AWS EC2 Instance Created and Setup
+- name: Final tasks
hosts: local
gather_facts: no
tasks:
- # - name: WebAPI Notification
- # ansible.builtin.uri:
- # url: '{{ webAPI }}'
- # method: POST
- # body_format: json
- # body:
- # username: "{{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }} Build Complete"
- # content: "Public IP - {{ item.public_ip_address }} \nPublic DNS - {{ item.public_dns_name }}"
- # avatar_url: "https://clipground.com/images/ansible-logo-clipart-5.png"
- # status_code:
- # - 200
- # - 202
- # - 204
- # loop: '{{ ec2.instances }}'
- # tags: default
-
- - name: Display AWS EC2 Information
- debug:
- msg:
- - "Instance Name - {{ semaphore_vars.task_details.username|upper }}-{{ imageName }} {{ hostvars[item.public_ip_address].productName }}"
- - 'AWS ID - {{ item.instance_id }}'
- - 'AWS Region - {{ awsRegion }}'
- - 'Public IP - {{ item.public_ip_address }}'
- - 'Public DNS - {{ item.public_dns_name }}'
- - 'Private IP - {{ item.private_ip_address }}'
- - 'Private DNS - {{ item.private_dns_name }}'
- loop: '{{ ec2.instances }}'
- tags: default
\ No newline at end of file
+ - name: Import final.yml
+ import_tasks: final.yml
+ tags: default
\ No newline at end of file