@RossKukulinski
SpeakIt.io Co-Founder
BayNode Talk Night
July 24, 2014
$ git push heroku master
$ jitsu deploy
Ansible is an open-source software platform for configuring and managing computers
“Ansible is infrastructure as data
(as opposed to infrastructure as code)”
- name: Add node apt repo
apt_repository: repo='ppa:chris-lea/node.js' state=present update_cache=yes
- name: Install node
apt: pkg=nodejs state=present
- name: Install global packages
npm: global=yes name={{ item }} state=present
with_items: nodejs_global_packages
- name: configure and deploy nginx load balancer
hosts: nginx-prod
user: root
roles:
- common
- nginx
- name: configure and deploy nodejs app
hosts: app-prod
user: root
roles:
- common
- nodejs-app
[app-prod]
162.1.2.3
162.1.2.4
[nginx-prod]
162.2.1.3
---
- hosts: localhost
gather_facts: False
vars_files:
- vars/keys.yml
- vars/droplets.yml
tasks:
- include: tasks/create_droplet.yml droplets={{droplets}}
---
droplets:
- name: production.nginx.1
- name: production.app.1
- name: production.mongodb.1
---
- name: ensure droplet exists
digital_ocean: >
state=present
command=droplet
name={{ item.name }}
ssh_key_ids={{ default_key }}
size_id={{ item.size|default(default_size) }}
region_id={{ item.region|default(default_region) }}
image_id={{ item.image|default(default_image) }}
private_networking=yes
wait_timeout=500
unique_name=true
register: droplet
with_items: droplets
ansible-playbook -i hosts site.yml
Special thanks to @jareddlc
- include: provision_digital_ocean.yml
# MongoDB Configuration
- hosts: production.mongodb.*
user: root
vars_files:
- vars/database.yml
tasks:
- name: Add production.mongodb.* to inventory
group_by: key="production.mongodb"
- name: setfact
set_fact: db_ip={{ ansible_eth1["ipv4"]["address"] }}
roles:
- common
- mongodb
# NodeJS Todo App Configuration
- hosts: production.app.*
user: root
vars_files:
- vars/database.yml
tasks:
- name: Add production.app.* to inventory
group_by: key="production.app"
- name: setfact
set_fact: http_ip={{ ansible_eth1["ipv4"]["address"] }}
roles:
- common
- nodejs
- app
module.exports = {
// the database url to connect
url : 'mongodb://
{%- for host in groups['production.mongodb'] -%}
{{ hostvars[host]['db_ip'] }}
{%- if loop.first -%}
/{{db_name}}
{% endif %}
{%- if loop.length > 1 and not loop.last -%}
,
{% endif %}
{% endfor %}';
}
// url : 'mongodb://10.128.190.31/node-todo,10.128.190.11,10.112.232.11'
# Nginx Configuration
- hosts: production.nginx.*
user: root
tasks:
- name: Add production.nginx.* to inventory
group_by: key="production.nginx"
roles:
- common
- nginx
# Simple Load Balancer
upstream static {
least_conn;
{% for host in groups['production.app'] %}
server {{ hostvars[host]['http_ip'] }}:8080;
{% endfor %}
}
server {
listen 80;
location / {
proxy_pass http://static/;
proxy_http_version 1.1;
proxy_next_upstream error timeout;
}
}