Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible 3 #9

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
93309f8
Add test-app HW
Aug 29, 2023
7649c7d
Add cloud-testapp HW
Aug 29, 2023
350922f
Add cloud-testapp HW
Aug 29, 2023
2059af1
Add cloud-testapp HW
Aug 29, 2023
76853dd
Add packer-base HW
Aug 29, 2023
8c8f95c
Add packer-base HW
Aug 29, 2023
191ff8e
Add terraform-1 HW
Aug 29, 2023
04d1d59
Add terraform-1 HW
Aug 29, 2023
c7b9672
Add terraform-1 HW
Aug 29, 2023
56d623b
Add terraform-1 HW
Aug 29, 2023
9a03e8e
Add terraform-2 HW
Aug 29, 2023
8f4936c
Add terraform-2 HW
Aug 29, 2023
f197cdb
Add terraform-2 HW
Aug 29, 2023
d604f61
Add terraform-2 HW
Aug 29, 2023
6958da2
Add terraform-2 HW
Aug 29, 2023
21c3fd9
Add terraform-2 HW
Aug 29, 2023
42e73f1
Add terraform-2 HW
Aug 29, 2023
b434948
Add terraform-2 HW
Aug 29, 2023
1cf7049
Add terraform-2 HW
Aug 29, 2023
f5a54b3
Add terraform-2 HW
Aug 29, 2023
f8d3ff0
ADD ansible-1 HW
Sep 1, 2023
b0bd2b2
Add ansible-1 HW
Sep 1, 2023
2b1ed72
Add ansible-1 HW
Sep 1, 2023
9e4bbfc
Add ansible-1 HW
Sep 1, 2023
bfc5a0f
Add ansible-2 HW
Sep 5, 2023
a49221a
Add ansible-2 HW
Sep 5, 2023
ee28a67
Add ansible-2 HW
Sep 5, 2023
87cfdfe
Add ansible-2 HW
Sep 5, 2023
a48069b
Add ansible-2 HW
Sep 14, 2023
0538efa
Add ansible-2 HW
Sep 14, 2023
6c385fd
Add ansible-2 HW
Sep 14, 2023
2a548fd
Add ansible-2 HW
Sep 14, 2023
a901e25
Add ansible-3 HW
Sep 14, 2023
99b0e42
Add ansible-3 HW
Sep 14, 2023
a470521
Add ansible-3 HW
Sep 14, 2023
f47602b
Add ansible-3 HW
Sep 14, 2023
6eceb69
Add ansible-3 HW
Sep 14, 2023
07d952b
Add ansible-3 HW
Sep 14, 2023
a37e675
Add ansible-3 HW
Sep 14, 2023
a3a298b
Add ansible-3 HW
Sep 14, 2023
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
8 changes: 4 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Выполнено ДЗ №

- [ ] Основное ДЗ
- [ ] Задание со *
- [x] Основное ДЗ
- [x] Задание со *

## В процессе сделано:
- Пункт 1
Expand All @@ -14,5 +14,5 @@
- Например, перейти по ссылке http://localhost:8080

## PR checklist
- [ ] Выставил label с номером домашнего задания
- [ ] Выставил label с темой домашнего задания
- [x] Выставил label с номером домашнего задания
- [x] Выставил label с темой домашнего задания
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variables.json
*.tfstate
*.tfstate.*.backup
*.tfstate.backup
*.tfvars
.terraform/
key.json
*.retry
jdauphant.nginx
File renamed without changes.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ HW3
Развернут OpenVPN
bastion_IP = 158.160.105.122
someinternalhost_IP = 10.128.0.34

HW4
Содана ВМ
Развернуты ruby mongodb и произведен деплой приложения
testapp_IP = 51.250.67.144
testapp_port = 9292

HW5
Создан файл ubuntu16.json
Развернут образ виртуальной машины
Создана ВМ из образа
Создан файл параметров
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[defaults]
inventory = ./ansible/environments/stage/inventory.yml
remote_user = ubuntu
private_key_file = ~/.ssh/appuser
# Отключим проверку SSH Host-keys (поскольку они всегда разные для новых инстансов)
host_key_checking = False
# Отключим создание *.retry-файлов (они нечасто нужны, но мешаются под руками)
retry_files_enabled = False
# Явно укажем расположение ролей (можно задать несколько путей через ; )
roles_path = ./ansible/roles
vault_password_file = ~/.ansible/vault.key
[diff]
# Включим обязательный вывод diff при наличии изменений и вывод 5 строк контекста
always = True
context = 5
15 changes: 15 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[defaults]
inventory = ./environments/stage/inventory.yml
remote_user = ubuntu
private_key_file = ~/.ssh/appuser
# Отключим проверку SSH Host-keys (поскольку они всегда разные для новых инстансов)
host_key_checking = False
# Отключим создание *.retry-файлов (они нечасто нужны, но мешаются под руками)
retry_files_enabled = False
# Явно укажем расположение ролей (можно задать несколько путей через ; )
roles_path = ./roles
vault_password_file = ~/.ansible/vault.key
[diff]
# Включим обязательный вывод diff при наличии изменений и вывод 5 строк контекста
always = True
context = 5
10 changes: 10 additions & 0 deletions ansible/environments/prod/credentials.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$ANSIBLE_VAULT;1.1;AES256
65373638393763363462316233656166363330363364643938383266363761626162343439666337
6539383737333635663239333762396534663566383034620a613835663730636533303734343232
66613438313663333765343935336631366339336639643535366231383366316564646261616533
6634663663383232340a643463653334353866636531336264636338663036336462633231373439
38626265333963323966356536333930396231363939346136316332393935303861323738343734
63336639396366353964366531393635663462666263663463613261663865383435626436346637
33643339633435633736666336323330303636313837383663343734346539313231383161663734
62633932633031633433396439633432363063623766623533353936313933323235323933666364
6538
1 change: 1 addition & 0 deletions ansible/environments/prod/group_vars/all
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env: prod
8 changes: 8 additions & 0 deletions ansible/environments/prod/group_vars/app
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
db_host: 158.160.115.131
nginx_sites:
default:
- listen 80
- server_name "reddit"
- location / {
proxy_pass http://127.0.0.1:9292;
}
1 change: 1 addition & 0 deletions ansible/environments/prod/group_vars/db
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mongo_bind_ip: 0.0.0.0
8 changes: 8 additions & 0 deletions ansible/environments/prod/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
app:
hosts:
appserver:
ansible_host: 51.250.75.14
db:
hosts:
dbserver:
ansible_host: 158.160.115.131
2 changes: 2 additions & 0 deletions ansible/environments/prod/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- src: jdauphant.nginx
version: v2.21.1
11 changes: 11 additions & 0 deletions ansible/environments/stage/credentials.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$ANSIBLE_VAULT;1.1;AES256
38336136653364383936346461666637383739313530313838626365353439663337643533643732
6133373334383835306136376561653532336562353162610a373562373065353938356364343534
35316366643935366531393834306433363162363634386236343735333065643764343066626564
3233636632336530350a373230373061653031316131373430663233623735653337626233313239
62313438383137343430373864646464343837363532346335626231636366343238323434633265
61366431613466376661303131353432383035663336663632393337313631646661616262616239
34393761383065623430373933333330313534366634326438643364623833393837313364643433
62303663653036316131323039633736363066353131363233343665643838333233363039363932
64316336303661626436333931313063326132323961666265383035356230636536386131316138
3865636264333466333136656566366430333732326462623331
1 change: 1 addition & 0 deletions ansible/environments/stage/group_vars/all
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env: stage
8 changes: 8 additions & 0 deletions ansible/environments/stage/group_vars/app
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
db_host: 158.160.115.131
nginx_sites:
default:
- listen 80
- server_name "reddit"
- location / {
proxy_pass http://127.0.0.1:9292;
}
1 change: 1 addition & 0 deletions ansible/environments/stage/group_vars/db
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mongo_bind_ip: 0.0.0.0
8 changes: 8 additions & 0 deletions ansible/environments/stage/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
app:
hosts:
appserver:
ansible_host: 51.250.75.14
db:
hosts:
dbserver:
ansible_host: 158.160.115.131
2 changes: 2 additions & 0 deletions ansible/environments/stage/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- src: jdauphant.nginx
version: v2.21.1
8 changes: 8 additions & 0 deletions ansible/old/clone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Clone
hosts: app
tasks:
- name: Clone repo
git:
repo: https://github.com/express42/reddit.git
version: monolith # <-- Указываем нужную ветку
dest: /home/ubuntu/reddit
14 changes: 14 additions & 0 deletions ansible/old/files/puma.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Puma HTTP Server
After=network.target

[Service]
Type=simple
EnvironmentFile=/home/ubuntu/db_config
User=ubuntu
WorkingDirectory=/home/ubuntu/reddit
ExecStart=/bin/bash -lc 'puma'
Restart=always

[Install]
WantedBy=multi-user.target
75 changes: 75 additions & 0 deletions ansible/old/reddit_app_multiple_plays.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
- name: Configure MongoDB
hosts: db
tags: db-tag
become: true
vars:
mongo_bind_ip: 0.0.0.0
tasks:
- name: Change mongo config file
template:
src: templates/mongod.conf.j2
dest: /etc/mongod.conf
mode: "0644"
notify: Restart mongod

handlers: # <-- Добавим блок handlers и задачу
- name: Restart mongod
service:
name: mongod
state: restarted

- name: Configure App
hosts: app
tags: app-tag
become: true
vars:
db_host: 158.160.115.131
tasks:
- name: Add unit file for Puma
copy:
src: files/puma.service
dest: /etc/systemd/system/puma.service
mode: preserve
notify: Restart puma

- name: Add config for DB connection
template:
src: templates/db_config.j2
dest: /home/ubuntu/db_config
mode: preserve

- name: Enable puma
systemd:
name: puma
enabled: true

handlers: # <-- Добавим блок handlers и задачу
- name: Restart puma
service:
name: puma
state: restarted


- name: Deploy App
hosts: app
tags: deploy-tag
become: true
tasks:
- name: Fetch the latest version of application code
git:
repo: 'https://github.com/express42/reddit.git'
dest: /home/ubuntu/reddit
version: monolith # <-- Указываем нужную ветку
notify: Restart puma

- name: Bundle install
bundler:
state: present
chdir: /home/ubuntu/reddit

handlers: # <-- Добавим блок handlers и задачу
- name: Restart puma
service:
name: puma
state: restarted
64 changes: 64 additions & 0 deletions ansible/old/reddit_app_one_play.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
- name: Configure hosts & deploy application
hosts: all
vars:
mongo_bind_ip: 0.0.0.0
db_host: 158.160.115.131
tasks:
- name: Change mongo config file
become: true
template:
src: templates/mongod.conf.j2
dest: /etc/mongod.conf
mode: "0644"
tags: db-tag
notify: Restart mongod

- name: Add unit file for Puma
become: true
copy:
src: ansible/files/puma.service
dest: /etc/systemd/system/puma.service
mode: preserve
tags: app-tag
notify: Restart puma

- name: Add config for DB connection
template:
src: templates/db_config.j2
dest: /home/ubuntu/db_config
mode: preserve
tags: app-tag

- name: Enable puma
become: true
systemd:
name: puma
enabled: true
tags: app-tag

- name: Fetch the latest version of application code
git:
repo: 'https://github.com/express42/reddit.git'
dest: /home/ubuntu/reddit
version: monolith # <-- Указываем нужную ветку
tags: deploy-tag
notify: Restart puma

- name: Bundle install
bundler:
state: present
chdir: /home/ubuntu/reddit
tags: deploy-tag

handlers: # <-- Добавим блок handlers и задачу
- name: Restart mongod
become: true
service:
name: mongod
state: restarted
- name: Restart puma
become: true
service:
name: puma
state: restarted
1 change: 1 addition & 0 deletions ansible/old/templates/db_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL={{ db_host }}
16 changes: 16 additions & 0 deletions ansible/old/templates/mongod.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true

# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log

# network interfaces
net:
port: {{ mongo_port | default('27017') }}
bindIp: {{ mongo_bind_ip }}
6 changes: 6 additions & 0 deletions ansible/playbooks/app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: Configure App
hosts: app
become: true
roles:
- app
- jdauphant.nginx
5 changes: 5 additions & 0 deletions ansible/playbooks/db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: Configure MongoDB
hosts: db
become: true
roles:
- db
21 changes: 21 additions & 0 deletions ansible/playbooks/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- name: Deploy App
hosts: app
become: true
tasks:
- name: Fetch the latest version of application code
git:
repo: 'https://github.com/express42/reddit.git'
dest: /home/ubuntu/reddit
version: monolith # <-- Указываем нужную ветку
notify: Restart puma

- name: Bundle install
bundler:
state: present
chdir: /home/ubuntu/reddit

handlers: # <-- Добавим блок handlers и задачу
- name: Restart puma
service:
name: puma
state: restarted
21 changes: 21 additions & 0 deletions ansible/playbooks/packer_app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Install Ruby && Bundler && Git
hosts: all
become: true
tasks:
# Установим в цикле все зависимости

- name: Install ruby and rubygems and required packages
apt:
name: "{{ item }}"
state: present
update_cache: true
with_items:
- ruby-full
- ruby-bundler
- build-essential
- name: Install git
apt:
name: git
state: present
update_cache: true
Loading