Skip to content

Instantly share code, notes, and snippets.

@kmurudi
Last active November 15, 2017 00:29
Show Gist options
  • Select an option

  • Save kmurudi/48e9ab971831664102e012bcbf9d775e to your computer and use it in GitHub Desktop.

Select an option

Save kmurudi/48e9ab971831664102e012bcbf9d775e to your computer and use it in GitHub Desktop.
---
- hosts: localhost
gather_facts: no
become: yes
tasks:
- name: Update all packages
apt:
update_cache: yes
upgrade: dist
- name: Add source key for nodejs
apt_key:
url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
state: present
register: first_run
- name: Add source repo for nodejs
apt_repository:
repo: "deb https://deb.nodesource.com/node_8.x xenial main"
state: present
update_cache: yes
- name: Add Ansible repo
apt_repository:
repo: "ppa:ansible/ansible"
state: present
update_cache: yes
- name: Install packages
apt:
name: "{{ item }}"
state: present
with_items:
- nginx
- mongodb
- nodejs
- ansible
- python-pymongo
- python-pip
- redis-server
- name: install pymongo
pip:
name: redis
state: present
- name: add mongo user
mongodb_user:
database: admin
name: admin
password: admin
roles: userAdminAnyDatabase
state: present
#when: first_run|changed
- name: Restart mongo
service:
name: mongodb
state: restarted
#when: first_run|changed
- name: clone checkbox repo
git:
repo: https://github.com/thegreyd/checkbox.io
dest: /home/ubuntu/checkbox
force: yes
update: yes
- name: configure nginx defaults
copy:
src: /home/ubuntu/checkbox/local-conf/default
dest: /etc/nginx/sites-available/default
force: yes
remote_src: True
#when: first_run|changed
- name: configure nginx conf
copy:
src: /home/ubuntu/checkbox/local-conf/nginx.conf
dest: /etc/nginx/nginx.conf
force: yes
remote_src: True
#when: first_run|changed
- name: Restart nginx
service:
name: nginx
state: restarted
#when: first_run|changed
- name: Replace bind in redis configuration
replace:
path: /etc/redis/redis.conf
regexp: 'bind 127.0.0.1'
replace: 'bind 0.0.0.0'
- name: setting this node as master
redis:
command: slave
slave_mode: master
- name: Start Redis server
command: redis-server --daemonize yes
- name: Restart Redis server
service:
name: redis-server
state: restarted
- name: npm install
npm:
path: /home/ubuntu/checkbox/server-side/site/
state: present
- name: start node server
environment:
MONGO_PORT: 3002
MONGO_IP: localhost
MONGO_USER: admin
MONGO_PASSWORD: admin
shell: node server.js
async: 2592000
poll: 0
args:
chdir: /home/ubuntu/checkbox/server-side/site/
...
---
- hosts: localhost
gather_facts: no
become: yes
tasks:
- name: Update all packages
apt:
update_cache: yes
upgrade: dist
- name: Add source key for nodejs
apt_key:
url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
state: present
register: first_run
- name: Add source repo for nodejs
apt_repository:
repo: "deb https://deb.nodesource.com/node_8.x xenial main"
state: present
update_cache: yes
- name: Add Ansible repo
apt_repository:
repo: "ppa:ansible/ansible"
state: present
update_cache: yes
- name: Install packages
apt:
name: "{{ item }}"
state: present
with_items:
- nginx
- mongodb
- nodejs
- ansible
- python-pymongo
- python-pip
- redis-server
- name: install pymongo
pip:
name: redis
state: present
- name: add mongo user
mongodb_user:
database: admin
name: admin
password: admin
roles: userAdminAnyDatabase
state: present
#when: first_run|changed
- name: Restart mongo
service:
name: mongodb
state: restarted
#when: first_run|changed
- name: clone checkbox repo
git:
repo: https://github.com/thegreyd/checkbox.io
dest: /home/ubuntu/checkbox
force: yes
update: yes
- name: configure nginx defaults
copy:
src: /home/ubuntu/checkbox/local-conf/default
dest: /etc/nginx/sites-available/default
force: yes
remote_src: True
#when: first_run|changed
- name: configure nginx conf
copy:
src: /home/ubuntu/checkbox/local-conf/nginx.conf
dest: /etc/nginx/nginx.conf
force: yes
remote_src: True
#when: first_run|changed
- name: Restart nginx
service:
name: nginx
state: restarted
#when: first_run|changed
- name: Replace bind in redis configuration
replace:
path: /etc/redis/redis.conf
regexp: 'bind 127.0.0.1'
replace: 'bind 0.0.0.0'
- name: setting this node as master
redis:
command: slave
master_host: redis_master
master_port: 6379
- name: Start Redis server
command: redis-server --daemonize yes
- name: Restart Redis server
service:
name: redis-server
state: restarted
- name: Comment set key line in server.js for slave
replace:
path: /home/ubuntu/checkbox/server-side/site/server.js
regexp: 'client.set("key1",1);'
replace: '//client.set("key1",1);'
- name: npm install
npm:
path: /home/ubuntu/checkbox/server-side/site/
state: present
- name: start node server
environment:
MONGO_PORT: 3002
MONGO_IP: localhost
MONGO_USER: admin
MONGO_PASSWORD: admin
shell: node server.js
async: 2592000
poll: 0
args:
chdir: /home/ubuntu/checkbox/server-side/site/
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment