Skip to content
Open
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
Binary file added assets/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions inventory.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[app]
client ansible_host=192.168.0.110 ansible_user=bez1

[db]
server ansible_host=192.168.0.122 ansible_user=bez2
9 changes: 9 additions & 0 deletions playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- hosts: db
become: yes
roles:
- mysql

- hosts: app
become: yes
roles:
- todo
48 changes: 48 additions & 0 deletions report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
### Предварительная настройка

Для выполнения задания создадим три виртуальные машины:
```
1. bez3@ansihost - на которой будет установлен ansible
2. bez2@server = 192.168.0.122
3. bez1@client =192.168.0.110
```

И прокидываем ssh соединение между ними. На хосте создаем ssh-ключ и копируем его публичную часть на остальные машины с помощью команд:
```
ssh-keygen -t ed25519 -C "ansible"
ssh-copy-id -i ~/.ssh/id_ed25519.pub bez2@192.168.0.122
ssh-copy-id -i ~/.ssh/id_ed25519.pub bez1@192.168.0.110
```

После загрузки ansible создаем простой inventory.ini для проверки связи

![img.png](assets/1.png)

И пингуем наши машины. В ответ на запрос получаем pong, значит соединение и аутентификация настроены правильно.

![img.png](assets/2.png)

### Создание проекта

Создаем структуру проекта:

![img.png](assets/3.png)

После чего определим роли для клиента и сервера.

![img.png](assets/4.png)

Создаем tasks для каждого из них где поочередно прописываем задачи, которые требуется выполнить:

![img.png](assets/5.png)

![img.png](assets/6.png)


Проект для развертывания готов. Копируем его на `bez3@ansihost` с помощью scp и запускаем playbook.

![img.png](assets/7.png)

Как видно из фото выше - запуск прошел успешно. Теперь запустим и проверим веб-приложение перейдя по адресу: http://192.168.0.110:3000/

![img.png](assets/8.png)
23 changes: 23 additions & 0 deletions roles/mysql/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- name: Установить Docker
apt:
name: docker.io
state: present
update_cache: true

- name: Запустить контейнер MySQL
docker_container:
name: mysql
image: mysql:5.7
state: started
restart_policy: always
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: todos
ports:
- "3306:3306"

- name: Разрешить входящий трафик на порт 3306
ufw:
rule: allow
port: 3306
proto: tcp
25 changes: 25 additions & 0 deletions roles/todo/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- name: Установить Docker
apt:
name: docker.io
state: present
update_cache: true

- name: Загрузить Docker-образ todo-app из Docker Hub
docker_image:
name: antonaleks/101-todo-app
tag: latest
source: pull

- name: Запустить контейнер todo-app
docker_container:
name: todo
image: antonaleks/101-todo-app:latest
state: started
restart_policy: always
ports:
- "3000:80"
env:
DB_HOST: 192.168.0.122
DB_USER: root
DB_PASSWORD: password
DB_NAME: todos