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
11 changes: 11 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[defaults]
inventory = inventory/hosts.ini
roles_path = roles
host_key_checking = False
remote_user = ubuntu
retry_files_enabled = False

[privilege_escalation]
become = True
become_method = sudo
become_user = root
19 changes: 19 additions & 0 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$ANSIBLE_VAULT;1.1;AES256
35336465303134613964303833633635643433323130356665333161663138303463386430613366
3235376538626464343264353032323736383661616664660a636230623861623332623035653838
38313561663366313639313831343631303238303064643465356230333935623235323135356166
6332613764646266330a643665386131386438633865656630383063646436393864343536646230
66646333343139343837373336323638623333393033363334343935343634666565303565663963
32353734303931373034386334333538313336386564356631383633383762356639343064363831
37343334333662356231386662343335313235633564303230656436613065303030663333336363
62373362643335383538353837353833383436393038336263373539616335613338383435393431
61376630396562633038303164333238313564333332346638623536316464346533323434303361
35616365663832363666646664313332353833363664626631363061316433393465373939616432
35393132323232633432363732303163636439316363613332663437643136353139613961613930
32646364363566336364636565386465643030613530663038343936313631386261666235376539
35376630363934313865336437313065333233653238663630636565363666353365376365363235
33633861353232616239376265393565373837303230313538333063623661396537643463303133
61306665653764633738613935636565373037633732623635643836333265333834653437636566
38653235353963643437643162356631306235363933326333326538656161306131663330333538
62623161663464363231373661633037346533326565393238303836343062323839386635303464
3038663062643465323631656564316330616239653230663866
9 changes: 9 additions & 0 deletions ansible/inventory/hosts.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[all]
ramzuka ansible_connection=local

[webservers]
ramzuka ansible_connection=local

[webservers:vars]
ansible_python_interpreter=/usr/bin/python3

7 changes: 7 additions & 0 deletions ansible/playbooks/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: Deploy application
hosts: all
gather_facts: yes
become: yes

roles:
- app_deploy
7 changes: 7 additions & 0 deletions ansible/playbooks/provisions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: Provision web servers
hosts: all
become: yes

roles:
- common
- docker
5 changes: 5 additions & 0 deletions ansible/roles/app_deploy/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
app_name: devops-app
docker_image_tag: latest
app_port: 5000
app_container_name: "{{ app_name }}"
restart_policy: unless-stopped
5 changes: 5 additions & 0 deletions ansible/roles/app_deploy/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: restart app
docker_container:
name: "{{ app_container_name }}"
state: started
restart: yes
54 changes: 54 additions & 0 deletions ansible/roles/app_deploy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
- name: Login to Docker Hub
docker_login:
username: ramzeus1
password: dckr_pat_pC4gjbebQ4Z4PAFVN4VcK8XTsAs
# no_log: true

- name: Pull Docker image
docker_image:
name: ramzeus1/devops-info-service
tag: "{{ docker_image_tag }}"
source: pull
force_source: yes

- name: Stop existing container
docker_container:
name: "{{ app_container_name }}"
state: stopped
ignore_errors: yes

- name: Remove existing container
docker_container:
name: "{{ app_container_name }}"
state: absent
ignore_errors: yes

- name: Run new container
docker_container:
name: "{{ app_container_name }}"
image: ramzeus1/devops-info-service:{{ docker_image_tag }}
state: started
restart_policy: "{{ restart_policy }}"
ports:
- "{{ app_port }}:5000"
env:
HOST: "0.0.0.0"
PORT: "5000"

- name: Wait for application to be ready
wait_for:
port: "{{ app_port }}"
host: 127.0.0.1
delay: 5
timeout: 30

- name: Verify health endpoint
uri:
url: http://127.0.0.1:{{ app_port }}/health
method: GET
status_code: 200
register: health_result

- name: Display health check
debug:
msg: "Health check: {{ health_result.json.status }} (uptime: {{ health_result.json.uptime_seconds }}s)"
8 changes: 8 additions & 0 deletions ansible/roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
common_packages:
- python3-pip
- curl
- git
- vim
- htop
- tree
- net-tools
10 changes: 10 additions & 0 deletions ansible/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Update apt cache
apt:
update_cache: yes
cache_valid_time: 3600

- name: Install common packages
apt:
name: "{{ common_packages }}"
state: present
1 change: 1 addition & 0 deletions ansible/roles/docker/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker_user: "{{ ansible_user }}"
4 changes: 4 additions & 0 deletions ansible/roles/docker/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: restart docker
service:
name: docker
state: restarted
40 changes: 40 additions & 0 deletions ansible/roles/docker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
- name: Add Docker GPG key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present

- name: Add Docker repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present

- name: Install Docker packages
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
update_cache: yes
state: present
notify: restart docker

- name: Ensure Docker is running and enabled
service:
name: docker
state: started
enabled: yes

- name: Add user to docker group
user:
name: "{{ docker_user }}"
groups: docker
append: yes
notify: restart docker

- name: Install python3-docker for Ansible modules
apt:
name: python3-docker
state: present
7 changes: 7 additions & 0 deletions ansible/test_all_vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: all
gather_facts: no
tasks:
- name: Show all variables for this host
debug:
var: vars
9 changes: 9 additions & 0 deletions ansible/test_role.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- hosts: all
gather_facts: yes
become: no
roles:
- role: app_deploy
vars:
dockerhub_password: "{{ dockerhub_password }}"
app_name: "{{ app_name }}"
10 changes: 10 additions & 0 deletions ansible/test_vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- hosts: all
become: no
tasks:
- name: Show dockerhub_username
debug:
var: dockerhub_username
- name: Show app_name
debug:
var: app_name
39 changes: 39 additions & 0 deletions app_python/docs/LAB04.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Lab 4 — Infrastructure as Code

## Cloud Provider & Infrastructure
- **Provider:** Local VM (VirtualBox)
- **Reason:** Free, full control, no cloud costs
- **VM Specs:** Ubuntu 24.04 LTS, 2GB RAM, 20GB disk, NAT + port forwarding (2222→22)
- **SSH Access:** `ssh devops@localhost -p 2222`

## Terraform Implementation
- **Version:** 1.9.8
- **Code:** Creates local files describing the VM
- **Files created:**
- `vm_terraform_info.txt` — VM information
- `ansible_inventory.ini` — Ansible inventory
- **Screenshot:** ![Terraform apply](screenshots/terraform-apply.png)

## Pulumi Implementation
- **Version:** latest
- **Language:** Python
- **Code:** Same functionality with Python
- **Files created:**
- `vm_pulumi_info.txt` — VM information
- `pulumi_ansible_inventory.ini` — Ansible inventory
- **Screenshot:** ![Pulumi up](screenshots/pulumi-up.png)

## Terraform vs Pulumi
| Aspect | Terraform | Pulumi |
|--------|-----------|--------|
| Language | HCL (declarative) | Python (imperative) |
| Learning | Easy syntax | Requires Python |
| Readability | Very clear | Flexible but more code |
| Debugging | Limited | Full Python debug |
| Best for | Pure infrastructure | Infra + app logic |

## Lab 5 Preparation
- Keeping VM running
- SSH: `ssh devops@localhost -p 2222`
- Ansible inventory: `ansible_inventory.ini`
- Docker ready to install when needed
Loading
Loading