-
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
1 parent
e1d17fc
commit 903df41
Showing
20 changed files
with
326 additions
and
69 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ packer/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,26 @@ | ||
--- | ||
- name: Configure App | ||
hosts: app | ||
become: true | ||
vars: | ||
db_host: 51.250.0.108 | ||
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: 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
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,19 @@ | ||
- name: Deploy App | ||
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 |
Empty file.
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: 84.201.128.233 | ||
ansible_host: 84.252.130.145 | ||
|
||
db: | ||
hosts: | ||
dbserver: | ||
ansible_host: 62.84.116.43 | ||
ansible_host: 51.250.0.108 |
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,24 @@ | ||
--- | ||
- name: Install MongoDB 3.2 | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: Add APT key | ||
apt_key: | ||
id: EA312927 | ||
keyserver: keyserver.ubuntu.com | ||
|
||
- 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,68 @@ | ||
--- | ||
- 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: 51.250.89.176 | ||
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: enable puma | ||
systemd: name=puma enabled=yes | ||
|
||
handlers: | ||
- name: reload puma | ||
systemd: name=puma state=reloaded | ||
|
||
|
||
- name: Deploy App | ||
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,56 @@ | ||
- name: Configure hosts & deploy application | ||
hosts: all | ||
vars: | ||
mongo_bind_ip: 0.0.0.0 | ||
db_host: 51.250.69.71 | ||
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: 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 | ||
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 | ||
tags: deploy-tag | ||
|
||
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,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 }} |
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,22 +1,22 @@ | ||
{ | ||
"builders": [ | ||
{ | ||
"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-base-{{timestamp}}", | ||
"image_family": "reddit-base", | ||
"ssh_username": "{{user `ssh_username`}}", | ||
"platform_id": "standard-v1", | ||
"use_ipv4_nat": "true" | ||
} | ||
], | ||
"provisioners": [ | ||
{ | ||
"type": "shell", | ||
"script": "scripts/install_ruby.sh", | ||
"execute_command": "sudo {{.Path}}" | ||
} | ||
] | ||
"builders": [ | ||
{ | ||
"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-{{timestamp}}", | ||
"image_family": "reddit-base", | ||
"ssh_username": "{{user `ssh_username`}}", | ||
"platform_id": "standard-v1", | ||
"use_ipv4_nat": "true" | ||
} | ||
], | ||
"provisioners": [ | ||
{ | ||
"type": "ansible", | ||
"user": "{{user `ssh_username`}}", | ||
"playbook_file": "ansible/packer_app.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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
{ | ||
"builders": [ | ||
{ | ||
"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-base-{{timestamp}}", | ||
"image_family": "reddit-base", | ||
"ssh_username": "{{user `ssh_username`}}", | ||
"platform_id": "standard-v1", | ||
"use_ipv4_nat": "true" | ||
} | ||
], | ||
"provisioners": [ | ||
{ | ||
"type": "shell", | ||
"script": "scripts/install_mongodb.sh", | ||
"execute_command": "sudo {{.Path}}" | ||
} | ||
] | ||
"builders": [ | ||
{ | ||
"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-db-{{timestamp}}", | ||
"image_family": "reddit-base", | ||
"ssh_username": "{{user `ssh_username`}}", | ||
"platform_id": "standard-v1", | ||
"use_ipv4_nat": "true" | ||
} | ||
], | ||
"provisioners": [ | ||
{ | ||
"type": "ansible", | ||
"user": "{{user `ssh_username`}}", | ||
"playbook_file": "ansible/packer_db.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
Oops, something went wrong.