Skip to content

Commit 5c6755e

Browse files
committed
documentation
1 parent ce7382a commit 5c6755e

File tree

6 files changed

+52
-33
lines changed

6 files changed

+52
-33
lines changed

README.md

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Ansible playbooks for launching and deploying a spring app
22

3-
The playbooks are designed to dynamically work with almost any spring app, the infrastructure is also designed to be scalable, fault-tolerant and highly available.
3+
The playbooks are designed to dynamically work with almost any spring app, the infrastructure is also built to be scalable, fault-tolerant and highly available.
4+
5+
The infrastructure is designed like the image below:
6+
7+
![alt text](aws-springapp-infrastructure.png)
8+
9+
![](aws-springapp-infrastructure.png)
410

511
### Requirements:
612

@@ -26,14 +32,14 @@ region = us-west-1
2632
[profile test-hello-app]
2733
region = us-west-2
2834
29-
[profile prod-time-app]
35+
[profile prod-time-app-east]
3036
region = us-east-1
3137
3238
[profile prod-time-app-west]
3339
region = us-west-1
3440
3541
```
36-
Sample ~/.aws/config
42+
Sample ~/.aws/credentials
3743
```
3844
[test-time-app]
3945
aws_access_key_id =
@@ -44,11 +50,20 @@ aws_secret_access_key =
4450

4551
#### Deploy the infrastrcture and the spring app
4652
- Configure the AMI for the user running the deployment, ec2,route53,sts,elasticloadbalancing,apigateway
47-
- We need to specify a git url to clone and configure the number of app instaces for each ec2 instance.
48-
the groups_vars/all file has all the default values
49-
- run the full deploy: AWS_DEFAULT_PROFILE=prod-time-app ansible-playbook -i hosts full_deploy.yml, note the env variable, you can surely specify it in different ways
53+
- We need to specify a git url for the app to clone, configure the number of app instaces for each ec2 instance in the groups_vars/all file, which has all the default values for our playbooks
54+
- Run the full deploy: AWS_DEFAULT_PROFILE=prod-time-app-east ansible-playbook -i hosts full_deploy.yml, note the env variable, you can surely specify it in different ways
55+
- During the play you will have two copy the public keys of the new instances to the git service, it will pause for two minutes, we can automate this for github or gitlab but for now its sufficient
5056
- deploy to another region by changing the AWS_DEFAULT_PROFILE to the desired profile/region. AWS_DEFAULT_PROFILE=prod-time-app-west ansible-playbook -i hosts full_deploy.yml
51-
- now as we have two regions running we can use route53 to load balance/health check on two elbs that have been created
52-
- Please note, name of aws_profile cannot contain characters that are not letters, or digits or dash (-)
57+
- now as we have two regions running we can use route53 to load balance/health check on two elbs that have been created, just run deploy_to_route53.yml with two env variables AWS_DEFAULT_PROFILE=prod-time-app-west and AWS_SECOND_PROFILE=prod-time-app-east
58+
- Please note, the name of aws_profile cannot contain characters that are not letters, or digits or dash (-)
59+
60+
61+
#### The full deploy
62+
- The full deploy is the starting point to run the infrastructure and the app we specify
63+
- 1. Create the aws needed services and servers, add to our route53 zone with the desired dns name for the load balancer(s) that has been created
64+
- 2. Install python on the target machines (in a raw fashion)
65+
- 3. Install common packages as well as nginx, haproxy to load balance app instances inside the ec2 instance
66+
- 4. Deploy the App, clone it, package it, run it and test it
67+
5368

5469

aws-springapp-infrastructure.png

93.6 KB
Loading

deploy_app.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
gather_facts: yes
1212
roles:
1313
- { role: haproxy, tags: ['haproxy'] } # haproxy installation and configuration, load balancing between spring apps
14-
- { role: rsyslog, tags: ['rsyslog'] } # rsyslog configuration, enable it for haproxy
1514
- { role: nginx, tags: ['nginx'] } # nginx installation and configuration, proxying to haproxy from elb.
16-
- { role: deploy_spring_app, tags: ['deploy_spring_app'] } # this is a collection of tasks to clone/checkout/package/run an app
15+
- { role: deploy_spring_app, tags: ['deploy_spring_app'] } # this is a collection of tasks to clone/checkout/package/run an app
16+
17+
# - { role: rsyslog, tags: ['rsyslog'] } # rsyslog configuration, enable it for haproxy
18+

full_deploy.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
roles:
99
- { role: aws_ec2_key, tags: ['aws_set_key'], when: create_ec2_instances } # Populate or create they key to be assigned to our instances
1010
- { role: aws_ec2_instances, tags: ['create_ec2_services'], when: create_ec2_instances } # At minimum, create two instances in two different 'available' Availablity-Zones
11-
11+
- { role: aws_route53, tags: ['create_route53_records'] }
12+
1213
- name: Pre-play install Python with raw command
1314
vars:
1415
aws_profile: "{{ lookup('env', 'AWS_DEFAULT_PROFILE') | default('test', true) }}" #shamelessly hacking hosts as a variable

roles/aws_route53/tasks/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
request_interval: 10
4040
failure_threshold: 2
4141
register: my_health_check_2
42-
when: aws_profile_2 is defined
42+
when: not aws_profile_2 == ""
4343

4444
- name: Add our dns record to route53 for the second region
4545
route53:
@@ -55,7 +55,7 @@
5555
alias: True
5656
alias_hosted_zone_id: "{{ hostvars[(groups[aws_profile_2] | last )].springappelb_zone }}"
5757
alias_evaluate_target_health: True
58-
when: aws_profile_2 is defined
58+
when: not aws_profile_2 == ""
5959

6060

6161

trial_error.yml

+21-20
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@
1212
AWS_DEFAULT_PROFILE: test
1313
tasks:
1414

15-
- name: Delete health check for route53 for the first region
16-
route53_health_check:
17-
state: absent
18-
fqdn: "{{ hostvars[(groups[aws_profile] | last )].springappelb_name }}"
19-
type: HTTP_STR_MATCH
20-
resource_path: /hello
21-
string_match: "hello"
22-
request_interval: 10
23-
failure_threshold: 2
24-
25-
- name: Delete Route53 record
26-
route53:
27-
state: absent
28-
zone: "{{ route53_zone }}"
29-
type: A
30-
record: "{{ hello_dns }}"
31-
value: "{{ hostvars[(groups[aws_profile] | last )].springappelb_name }}"
32-
15+
# - name: Delete health check for route53 for the first region
16+
# route53_health_check:
17+
# state: absent
18+
# fqdn: "{{ hostvars[(groups[aws_profile] | last )].springappelb_name }}"
19+
# type: HTTP_STR_MATCH
20+
# resource_path: /hello
21+
# string_match: "hello"
22+
# request_interval: 10
23+
# failure_threshold: 2
24+
#
25+
# - name: Delete Route53 record
26+
# route53:
27+
# state: absent
28+
# zone: "{{ route53_zone }}"
29+
# type: A
30+
# record: "{{ hello_dns }}"
31+
# value: "{{ hostvars[(groups[aws_profile] | last )].springappelb_name }}"
32+
#
3333
# - block:
3434
# - debug: var=item
3535
# with_flattened:
@@ -49,8 +49,9 @@
4949
# pause: seconds="120"
5050
# when: 'not "home" in test_response.content'
5151

52-
# - name: test env
53-
# debug: msg="{{ lookup('env', 'AWS_DEFAULT_PROFILE') }}"
52+
- name: test env
53+
debug: msg="{{ aws_profile_2 }}"
54+
when: not aws_profile_2 == ""
5455

5556
# - name: Link python3 to python in bin dir
5657
# file:

0 commit comments

Comments
 (0)