Skip to content

sudo instead of root #24

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ Tool to deploy [Elixir](http://elixir-lang.org/) & [Phoenix](http://www.phoenixf

```sh
$ pip install ansible
$ ansible-galaxy install HashNuke.elixir-stack
$ cd your_project/
$ ansible-galaxy install -p roles HashNuke.elixir-stack

# assuming your SSH key is called `id_rsa`
# run this everytime you start your computer
@@ -41,13 +42,22 @@ defp deps do
end
```

2.) In your project dir, run following command:
2.) Move `elixir-stack.sh` in to your project's root directory

```sh
$ curl -L http://git.io/ansible-elixir-stack.sh | bash
$ cd your_project/
$ mv playbooks/roles/HashNuke.elixir-stack/elixir-stack.sh elixir-stack.sh
```

**FOLLOW INSTRUCTIONS OF ABOVE COMMAND**
3.) Edit remote_user, add your server's IP addresses in `elixir-stack.sh`.

4.) Run the script

```sh
$ sh elixir-stack.sh
```

**FOLLOW INSTRUCTIONS GIVEN BY ABOVE COMMAND**

> Checkout the [documentation on configuration options](docs/configuration.md)

2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
git_ref: "master"

projects_dir: "/home/{{ deployer }}/projects"
projects_dir: "~{{ deployer }}/projects"
project_path: "{{ projects_dir }}/{{ app_name }}"

deploy_type: "restart"
11 changes: 7 additions & 4 deletions elixir-stack.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env sh

# Run this script from your project's root directory

app_name=$(grep -m 1 -oh 'app: :[[:alnum:]_]*' mix.exs | sed 's/app:\ ://')
remote_user='remote_user' # Replace with remote username
git_repo_url=$(git config --get remote.origin.url)
mkdir -p playbooks/vars playbooks/templates

cat > playbooks/setup.yml <<EOF
---
- hosts: app-servers
remote_user: root
remote_user: $remote_user
vars_files:
- vars/main.yml

@@ -19,7 +22,7 @@ EOF
cat > playbooks/deploy.yml <<EOF
---
- hosts: app-servers
remote_user: root
remote_user: $remote_user
vars_files:
- vars/main.yml

@@ -31,7 +34,7 @@ EOF
cat > playbooks/migrate.yml <<EOF
---
- hosts: app-servers
remote_user: root
remote_user: $remote_user
vars_files:
- vars/main.yml

@@ -43,7 +46,7 @@ EOF
cat > playbooks/remove-app.yml <<EOF
---
- hosts: app-servers
remote_user: root
remote_user: $remote_user
vars_files:
- vars/main.yml

1 change: 1 addition & 0 deletions tasks/action-deploy.yml
Original file line number Diff line number Diff line change
@@ -14,4 +14,5 @@


- name: start nginx using monit
sudo: yes
monit: name="nginx" state=started
1 change: 1 addition & 0 deletions tasks/action-remove-app.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- name: stop app
sudo: yes
monit: name="{{ app_name }}" state=stopped
ignore_errors: True

3 changes: 3 additions & 0 deletions tasks/action-setup.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@


- when: create_swap_file == True and swap_info.stat.exists == False
sudo: yes
include: create-swap-file.yml


@@ -36,8 +37,10 @@


- name: start nginx using monit
sudo: yes
monit: name="nginx" state=started


- name: reload nginx config
sudo: yes
service: name=nginx state=reloaded
1 change: 1 addition & 0 deletions tasks/common.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- name: "install system packages"
sudo: yes
apt: name="{{ item }}" update_cache=yes state=present
with_items:
- gcc
10 changes: 7 additions & 3 deletions tasks/deployer-user.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- name: "create deployer user"
sudo: yes
user: name="{{deployer}}" shell=/bin/bash


@@ -9,15 +10,18 @@


- name: "create .ssh dir for deployer"
file: path="/home/{{ deployer }}/.ssh" state=directory
sudo: yes
file: path="~{{ deployer }}/.ssh" state=directory


- name: "copy authorized keys to deployer user"
shell: "echo '{{root_authorized_keys.stdout}}' > /home/{{deployer}}/.ssh/authorized_keys"
sudo: yes
shell: "echo '{{root_authorized_keys.stdout}}' > ~{{deployer}}/.ssh/authorized_keys"


- name: "chown the authorized_keys file"
file: path="/home/{{deployer}}/.ssh" recurse=yes mode=0700 owner="{{ deployer }}"
sudo: yes
file: path="~{{deployer}}/.ssh" recurse=yes mode=0700 owner="{{ deployer }}"


- name: "ensure projects directory"
4 changes: 4 additions & 0 deletions tasks/monit.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
- name: install monit
sudo: yes
apt: name=monit update_cache=yes


- name: allow localhost access in monit config
sudo: yes
lineinfile: dest=/etc/monit/monitrc line="{{ item }}"
with_items:
- "set httpd port 2812 and"
@@ -33,12 +35,14 @@


- name: add monit config for elixir app
sudo: yes
template:
src: app.monit.j2
dest: "/etc/monit/conf.d/{{ app_name }}.monit"


- name: add monit config for nginx
sudo: yes
template:
src: nginx.monit.j2
dest: "/etc/monit/conf.d/nginx.monit"
6 changes: 6 additions & 0 deletions tasks/nginx.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
---
- name: add nginx pkg repo
sudo: yes
apt_repository: repo="ppa:nginx/stable"


- name: install nginx
sudo: yes
apt: name=nginx update_cache=yes state=present


- name: "disable nginx and don't start service on reboot"
sudo: yes
service: name=nginx enabled=no state=stopped


- name: remove nginx default configs
sudo: yes
file: name="{{ item }}" state=absent
with_items:
- /etc/nginx/sites-available/default
- /etc/nginx/sites-enabled/default


- name: add nginx config for elixir app
sudo: yes
template:
src: app.nginx.j2
dest: "/etc/nginx/sites-available/{{ app_name }}.nginx"


- name: enable elixir app to be served by nginx
sudo: yes
file:
src: "/etc/nginx/sites-available/{{ app_name }}.nginx"
dest: "/etc/nginx/sites-enabled/{{ app_name }}.nginx"
1 change: 1 addition & 0 deletions tasks/pip.yml
Original file line number Diff line number Diff line change
@@ -4,4 +4,5 @@


- name: "install pip"
sudo: yes
command: "python /tmp/get-pip.py"
4 changes: 4 additions & 0 deletions tasks/postgres.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
---
- name: "add postgres repository"
sudo: yes
apt_repository: repo="deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main"


- name: "add postgres repository key"
sudo: yes
apt_key: url="https://www.postgresql.org/media/keys/ACCC4CF8.asc"


- name: "install postgres & libpq-dev"
sudo: yes
apt: name="{{ item }}" update_cache=yes state=present
with_items:
- postgresql-9.4
- libpq-dev


- name: install psycopg2 python module
sudo: yes
pip: name=psycopg2


3 changes: 3 additions & 0 deletions tasks/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
- when: deploy_type == "restart"
sudo: yes
name: stop app
monit: name="{{ app_name }}" state=stopped
ignore_errors: true


- when: deploy_type == "restart"
@@ -19,6 +21,7 @@


- when: deploy_type == "restart"
sudo: yes
name: start app
monit: name="{{ app_name }}" state=started