Skip to content

Commit bcdf68b

Browse files
authored
Merge pull request #9 from qobz1e/lab05
Lab05
2 parents 8536e21 + 76623b5 commit bcdf68b

15 files changed

Lines changed: 170 additions & 1 deletion

File tree

ansible/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vault_pass

ansible/ansible.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[defaults]
2+
inventory = inventory/hosts.ini
3+
roles_path = roles
4+
host_key_checking = False
5+
remote_user = ubuntu
6+
retry_files_enabled = False
7+
8+
[privilege_escalation]
9+
become = True
10+
become_method = sudo
11+
become_user = root

ansible/group_vars/all.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
docker_image: qobz1e/devops-info-service
2+
docker_image_tag: lab2
3+
app_container_name: info-service
4+
app_port: 5000
5+
restart_policy: always
6+
env_vars:
7+
ENV: production
8+
dockerhub_username: qobz1e
9+
dockerhub_password: !vault |
10+
$ANSIBLE_VAULT;1.1;AES256
11+
61326164653039343162646236626431386632643166396130626164316238633363616231616131
12+
6462663662386465373263666262626433353832313962660a613635623639306130633134656434
13+
32623434383237333532363630383264323464343563366266336230303266326661616237353064
14+
3337303165653736640a373561613836373639303237373032393134336464613732346161653664
15+
65396237363265336236623361326135346238613065656131656265353737323363303034343133
16+
6531623765633839623039323131666530646464306133373030

ansible/inventory/hosts.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[webservers]
2+
myvm ansible_host=130.193.51.239 ansible_user=ubuntu ansible_ssh_private_key_file=/workspaces/DevOps-Core-Course/labs/id_rsa
3+
4+
[webservers:vars]
5+
ansible_python_interpreter=/usr/bin/python3

ansible/playbooks/deploy.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Deploy application
3+
hosts: webservers
4+
become: yes
5+
vars_files:
6+
- /workspaces/DevOps-Core-Course/ansible/group_vars/all.yml
7+
roles:
8+
- app_deploy

ansible/playbooks/provision.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Provision web servers
3+
hosts: webservers
4+
become: yes
5+
6+
roles:
7+
- common
8+
- docker
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
app_port: 5000
3+
restart_policy: unless-stopped
4+
env_vars: {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: restart app container
3+
community.docker.docker_container:
4+
name: "{{ app_container_name }}"
5+
state: restarted
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
- name: Login to Docker Hub
3+
community.docker.docker_login:
4+
username: "{{ dockerhub_username }}"
5+
password: "{{ dockerhub_password }}"
6+
no_log: true
7+
8+
- name: Pull Docker image
9+
community.docker.docker_image:
10+
name: "{{ docker_image }}"
11+
tag: "{{ docker_image_tag }}"
12+
source: pull
13+
14+
- name: Stop existing container
15+
community.docker.docker_container:
16+
name: "{{ app_container_name }}"
17+
state: stopped
18+
ignore_errors: yes
19+
20+
- name: Remove old container
21+
community.docker.docker_container:
22+
name: "{{ app_container_name }}"
23+
state: absent
24+
ignore_errors: yes
25+
26+
- name: Run application container
27+
community.docker.docker_container:
28+
name: "{{ app_container_name }}"
29+
image: "{{ docker_image }}:{{ docker_image_tag }}"
30+
state: started
31+
restart_policy: "{{ restart_policy }}"
32+
published_ports:
33+
- "{{ app_port }}:{{ app_port }}"
34+
env:
35+
"{{ env_vars }}"
36+
37+
- name: Wait for application to be ready
38+
wait_for:
39+
host: 127.0.0.1
40+
port: "{{ app_port }}"
41+
delay: 5
42+
timeout: 30
43+
44+
- name: Verify health endpoint
45+
uri:
46+
url: "http://127.0.0.1:{{ app_port }}/health"
47+
status_code: 200
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
common_packages:
2+
- python3-pip
3+
- curl
4+
- git
5+
- vim
6+
- htop

0 commit comments

Comments
 (0)