-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
345 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ variables.json | |
*.tfstate.backup | ||
*.tfvars | ||
.terraform/ | ||
*.retry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
- name: Configure App | ||
hosts: app | ||
become: true | ||
vars: | ||
db_host: 172.16.72.4 | ||
tasks: | ||
- name: Add unit file for Puma | ||
copy: | ||
src: files/puma.service | ||
dest: /etc/systemd/system/puma.service | ||
notify: reload puma | ||
|
||
- name: Add config for DB connection | ||
template: | ||
src: templates/db_config.j2 | ||
dest: /home/ubuntu/db_config | ||
owner: ubuntu | ||
group: ubuntu | ||
|
||
- name: Install git | ||
apt: | ||
name: git | ||
state: present | ||
update_cache: yes | ||
|
||
- name: enable puma | ||
systemd: name=puma enabled=yes | ||
|
||
handlers: | ||
- name: reload puma | ||
systemd: name=puma state=restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
- name: Configure MongoDB | ||
hosts: db | ||
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: | ||
- name: restart mongod | ||
service: name=mongod state=restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
- name: Deploy | ||
hosts: app | ||
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: | ||
- name: restart puma | ||
become: true | ||
systemd: name=puma state=restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[app] | ||
appserver ansible_host=158.160.107.84 | ||
appserver ansible_host=158.160.50.91 | ||
[db] | ||
dbserver ansible_host=158.160.50.213 | ||
dbserver ansible_host=158.160.34.79 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
app: | ||
hosts: | ||
appserver: | ||
ansible_host: 158.160.107.84 | ||
ansible_host: 158.160.58.127 | ||
|
||
db: | ||
hosts: | ||
dbserver: | ||
ansible_host: 158.160.50.213 | ||
ansible_host: 158.160.112.75 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Install Ruby && Bundler | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: Install ruby and rubygems and required packages | ||
apt: "name={{ item }} state=present" | ||
with_items: | ||
- ruby-full | ||
- ruby-bundler | ||
- build-essential |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
- name: Install MongoDB 3.2 | ||
hosts: db | ||
become: true | ||
tasks: | ||
# Добавим ключ репозитория для последующей работы с ним | ||
- name: Add APT key | ||
apt_key: | ||
id: EA312927 | ||
keyserver: keyserver.ubuntu.com | ||
|
||
# Подключаем репозиторий с пакетами mongodb | ||
- name: Add APT repository | ||
apt_repository: | ||
repo: deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse | ||
state: present | ||
|
||
# Выполним установку пакета | ||
- name: Install mongodb package | ||
apt: | ||
name: mongodb-org | ||
state: present | ||
|
||
# Включаем сервис | ||
- name: Configure service supervisor | ||
systemd: | ||
name: mongod | ||
enabled: yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
- 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: | ||
- name: restart mongod | ||
service: name=mongod state=restarted | ||
|
||
- name: Configure App | ||
hosts: app | ||
tags: app-tag | ||
become: true | ||
vars: | ||
db_host: 172.16.72.4 | ||
tasks: | ||
- name: Add unit file for Puma | ||
copy: | ||
src: files/puma.service | ||
dest: /etc/systemd/system/puma.service | ||
notify: reload puma | ||
|
||
- name: Add config for DB connection | ||
template: | ||
src: templates/db_config.j2 | ||
dest: /home/ubuntu/db_config | ||
owner: ubuntu | ||
group: ubuntu | ||
|
||
- name: Install git | ||
apt: | ||
name: git | ||
state: present | ||
update_cache: yes | ||
|
||
- name: enable puma | ||
systemd: name=puma enabled=yes | ||
|
||
handlers: | ||
- name: reload puma | ||
systemd: name=puma state=restarted | ||
|
||
- name: Deploy | ||
hosts: app | ||
tags: deploy-tag | ||
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: | ||
- name: restart puma | ||
become: true | ||
systemd: name=puma state=restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
- name: Configure hosts & deploy application | ||
hosts: all | ||
vars: | ||
mongo_bind_ip: 0.0.0.0 # <-- Переменная задается в блоке vars | ||
db_host: 172.16.72.32 | ||
tasks: | ||
- name: Change mongo config file | ||
become: true # <-- Выполнить задание от root | ||
template: | ||
src: templates/mongod.conf.j2 # <-- Путь до локального файла-шаблона | ||
dest: /etc/mongod.conf # <-- Путь на удаленном хосте | ||
mode: 0644 | ||
tags: db-tag | ||
- name: Add unit file for Puma | ||
become: true | ||
copy: | ||
src: files/puma.service | ||
dest: /etc/systemd/system/puma.service | ||
tags: app-tag | ||
notify: reload puma | ||
- name: Add config for DB connection | ||
template: | ||
src: templates/db_config.j2 | ||
dest: /home/ubuntu/db_config | ||
tags: app-tag | ||
- name: enable puma | ||
become: true | ||
systemd: name=puma enabled=yes | ||
tags: app-tag | ||
- name: Fetch the latest version of application code | ||
#become: true | ||
#become_user: "ubuntu" | ||
git: | ||
repo: 'https://github.com/express42/reddit.git' | ||
dest: /home/ubuntu/reddit | ||
version: monolith # <-- Указываем нужную ветку | ||
tags: deploy-tag | ||
notify: reload puma | ||
- name: Bundle install | ||
bundler: | ||
state: present | ||
chdir: /home/ubuntu/reddit # <-- В какой директории выполнить команду bundle | ||
tags: deploy-tag | ||
|
||
handlers: # <-- Добавим блок handlers и задачу | ||
- name: restart mongod | ||
become: true | ||
service: name=mongod state=restarted | ||
- name: reload puma | ||
become: true | ||
systemd: name=puma state=restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
- import_playbook: db.yml | ||
- import_playbook: app.yml | ||
- import_playbook: deploy.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URL={{ db_host }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 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: | ||
# default - один из фильтров Jinja2, он задает значение по умолчанию, | ||
# если переменная слева не определена | ||
port: {{ mongo_port | default('27017') }} | ||
bindIp: {{ mongo_bind_ip }} # <-- Подстановка значения переменной |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
{ | ||
"builders": [ | ||
"builders": [ | ||
{ | ||
"type": "yandex", | ||
"service_account_key_file": "/home/c3nt/otus/devops/c3ntik_infra/packer/key.json", | ||
"folder_id": "b1gi8rea67r233k0htdp", | ||
"subnet_id": "e9bliv6sqtuf7647rnrv", | ||
"zone": "{{user `zone`}}", | ||
"source_image_family": "ubuntu-1604-lts", | ||
"use_ipv4_nat": "true", | ||
"image_name": "reddit-app-{{timestamp}}", | ||
"image_family": "reddit-app", | ||
"disk_size_gb": "10", | ||
"ssh_username": "ubuntu", | ||
"platform_id": "standard-v1" | ||
"type": "yandex", | ||
"service_account_key_file": "{{user `service_account_key_file`}}", | ||
"folder_id": "{{user `folder_id`}}", | ||
"source_image_family": "{{user `source_image_family`}}", | ||
"image_name": "reddit-app-base-{{timestamp}}", | ||
"image_family": "reddit-app-base", | ||
"ssh_username": "ubuntu", | ||
"platform_id": "standard-v1", | ||
"use_ipv4_nat": "true", | ||
"disk_name": "reddit-app", | ||
"zone": "ru-central1-a" | ||
} | ||
], | ||
"provisioners": [ | ||
{ | ||
"type": "shell", | ||
"script": "scripts/install_ruby.sh", | ||
"execute_command": "sudo {{.Path}}" | ||
} | ||
] | ||
} | ||
], | ||
"provisioners": [ | ||
{ | ||
"type": "ansible", | ||
"user": "ubuntu", | ||
"playbook_file": "../ansible/packer_app.yml" | ||
} | ||
] | ||
} |
Oops, something went wrong.