Skip to content

Commit 7b5770f

Browse files
committed
lab5
1 parent 9e1527a commit 7b5770f

16 files changed

Lines changed: 206 additions & 0 deletions

File tree

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
$ANSIBLE_VAULT;1.1;AES256
2+
35336465303134613964303833633635643433323130356665333161663138303463386430613366
3+
3235376538626464343264353032323736383661616664660a636230623861623332623035653838
4+
38313561663366313639313831343631303238303064643465356230333935623235323135356166
5+
6332613764646266330a643665386131386438633865656630383063646436393864343536646230
6+
66646333343139343837373336323638623333393033363334343935343634666565303565663963
7+
32353734303931373034386334333538313336386564356631383633383762356639343064363831
8+
37343334333662356231386662343335313235633564303230656436613065303030663333336363
9+
62373362643335383538353837353833383436393038336263373539616335613338383435393431
10+
61376630396562633038303164333238313564333332346638623536316464346533323434303361
11+
35616365663832363666646664313332353833363664626631363061316433393465373939616432
12+
35393132323232633432363732303163636439316363613332663437643136353139613961613930
13+
32646364363566336364636565386465643030613530663038343936313631386261666235376539
14+
35376630363934313865336437313065333233653238663630636565363666353365376365363235
15+
33633861353232616239376265393565373837303230313538333063623661396537643463303133
16+
61306665653764633738613935636565373037633732623635643836333265333834653437636566
17+
38653235353963643437643162356631306235363933326333326538656161306131663330333538
18+
62623161663464363231373661633037346533326565393238303836343062323839386635303464
19+
3038663062643465323631656564316330616239653230663866

ansible/inventory/hosts.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[all]
2+
ramzuka ansible_connection=local
3+
4+
[webservers]
5+
ramzuka ansible_connection=local
6+
7+
[webservers:vars]
8+
ansible_python_interpreter=/usr/bin/python3
9+

ansible/playbooks/deploy.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- name: Deploy application
2+
hosts: all
3+
gather_facts: yes
4+
become: yes
5+
6+
roles:
7+
- app_deploy

ansible/playbooks/provisions.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- name: Provision web servers
2+
hosts: all
3+
become: yes
4+
5+
roles:
6+
- common
7+
- docker
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
app_name: devops-app
2+
docker_image_tag: latest
3+
app_port: 5000
4+
app_container_name: "{{ app_name }}"
5+
restart_policy: unless-stopped
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- name: restart app
2+
docker_container:
3+
name: "{{ app_container_name }}"
4+
state: started
5+
restart: yes
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
- name: Login to Docker Hub
2+
docker_login:
3+
username: ramzeus1
4+
password: dckr_pat_pC4gjbebQ4Z4PAFVN4VcK8XTsAs
5+
# no_log: true
6+
7+
- name: Pull Docker image
8+
docker_image:
9+
name: ramzeus1/devops-info-service
10+
tag: "{{ docker_image_tag }}"
11+
source: pull
12+
force_source: yes
13+
14+
- name: Stop existing container
15+
docker_container:
16+
name: "{{ app_container_name }}"
17+
state: stopped
18+
ignore_errors: yes
19+
20+
- name: Remove existing container
21+
docker_container:
22+
name: "{{ app_container_name }}"
23+
state: absent
24+
ignore_errors: yes
25+
26+
- name: Run new container
27+
docker_container:
28+
name: "{{ app_container_name }}"
29+
image: ramzeus1/devops-info-service:{{ docker_image_tag }}
30+
state: started
31+
restart_policy: "{{ restart_policy }}"
32+
ports:
33+
- "{{ app_port }}:5000"
34+
env:
35+
HOST: "0.0.0.0"
36+
PORT: "5000"
37+
38+
- name: Wait for application to be ready
39+
wait_for:
40+
port: "{{ app_port }}"
41+
host: 127.0.0.1
42+
delay: 5
43+
timeout: 30
44+
45+
- name: Verify health endpoint
46+
uri:
47+
url: http://127.0.0.1:{{ app_port }}/health
48+
method: GET
49+
status_code: 200
50+
register: health_result
51+
52+
- name: Display health check
53+
debug:
54+
msg: "Health check: {{ health_result.json.status }} (uptime: {{ health_result.json.uptime_seconds }}s)"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
common_packages:
2+
- python3-pip
3+
- curl
4+
- git
5+
- vim
6+
- htop
7+
- tree
8+
- net-tools
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Update apt cache
3+
apt:
4+
update_cache: yes
5+
cache_valid_time: 3600
6+
7+
- name: Install common packages
8+
apt:
9+
name: "{{ common_packages }}"
10+
state: present

0 commit comments

Comments
 (0)