Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
# Web app configuration
app_name: devops-app
docker_image: qobz1e/devops-info-service
docker_image_tag: lab2
app_container_name: info-service
app_port: 5000
restart_policy: always
env_vars:
ENV: production
docker_tag: lab2
app_port: 8000
app_internal_port: 8000
compose_project_dir: "/opt/{{ app_name }}"
docker_compose_version: "3.8"
dockerhub_username: qobz1e
dockerhub_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
Expand All @@ -13,4 +15,5 @@ dockerhub_password: !vault |
32623434383237333532363630383264323464343563366266336230303266326661616237353064
3337303165653736640a373561613836373639303237373032393134336464613732346161653664
65396237363265336236623361326135346238613065656131656265353737323363303034343133
6531623765633839623039323131666530646464306133373030
6531623765633839623039323131666530646464306133373030
web_app_wipe: false
8 changes: 4 additions & 4 deletions ansible/playbooks/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name: Deploy application
hosts: webservers
become: yes
- name: Deploy Web Application
hosts: all
become: true
vars_files:
- /workspaces/DevOps-Core-Course/ansible/group_vars/all.yml
roles:
- app_deploy
- web_app
4 changes: 0 additions & 4 deletions ansible/roles/app_deploy/defaults/main.yml

This file was deleted.

47 changes: 0 additions & 47 deletions ansible/roles/app_deploy/tasks/main.yml

This file was deleted.

14 changes: 14 additions & 0 deletions ansible/roles/web_app/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# Application variables
app_name: devops-app
docker_image: your_dockerhub_username/devops-info-service
docker_tag: latest
app_port: 8000
app_internal_port: 8000

# Docker Compose
compose_project_dir: "/opt/{{ app_name }}"
docker_compose_version: "3.8"

# Wipe logic
web_app_wipe: false
3 changes: 3 additions & 0 deletions ansible/roles/web_app/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- role: docker
34 changes: 34 additions & 0 deletions ansible/roles/web_app/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# Include wipe logic first
- name: Include wipe tasks
include_tasks: wipe.yml
tags:
- web_app_wipe

# Deployment block
- name: Deploy application with Docker Compose
block:
- name: Create app directory
file:
path: /opt/{{ app_name }}
state: directory
mode: '0755'

- name: Template docker-compose.yml
template:
src: docker-compose.yml.j2
dest: /opt/{{ app_name }}/docker-compose.yml

- name: Deploy with docker-compose
shell: docker compose up -d --build
args:
chdir: "/opt/{{ app_name }}"

rescue:
- name: Handle deployment failure
debug:
msg: "Deployment failed for {{ app_name }}"

tags:
- app_deploy
- compose
23 changes: 23 additions & 0 deletions ansible/roles/web_app/tasks/wipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Wipe web application
block:
- name: Stop and remove containers
community.docker.docker_compose:
project_src: /opt/{{ app_name }}
state: absent
remove_images: all
ignore_errors: yes

- name: Remove application directory
file:
path: /opt/{{ app_name }}
state: absent
ignore_errors: yes

- name: Log wipe completion
debug:
msg: "Application {{ app_name }} wiped successfully"

when: web_app_wipe | bool
tags:
- web_app_wipe
9 changes: 9 additions & 0 deletions ansible/roles/web_app/templates/docker-compose.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.8'

services:
{{ app_name }}:
image: {{ docker_image }}:{{ docker_tag }}
container_name: {{ app_name }}
ports:
- "{{ app_port }}:{{ app_internal_port }}"
restart: unless-stopped
Loading