From 541acc6975b1c01135ef994978962604ec03b196 Mon Sep 17 00:00:00 2001 From: Arunvel Sriram Date: Thu, 28 Jan 2016 14:55:10 +0530 Subject: [PATCH 1/4] Extract remote_user to a variable so that its value is not root by default --- elixir-stack.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/elixir-stack.sh b/elixir-stack.sh index f21aa5f..fefe7c6 100644 --- a/elixir-stack.sh +++ b/elixir-stack.sh @@ -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 < playbooks/deploy.yml < playbooks/migrate.yml < playbooks/remove-app.yml < Date: Thu, 28 Jan 2016 14:58:10 +0530 Subject: [PATCH 2/4] Add sudo for escalated commands --- tasks/action-deploy.yml | 1 + tasks/action-remove-app.yml | 1 + tasks/action-setup.yml | 3 +++ tasks/common.yml | 1 + tasks/deployer-user.yml | 4 ++++ tasks/monit.yml | 4 ++++ tasks/nginx.yml | 6 ++++++ tasks/pip.yml | 1 + tasks/postgres.yml | 4 ++++ tasks/release.yml | 3 +++ 10 files changed, 28 insertions(+) diff --git a/tasks/action-deploy.yml b/tasks/action-deploy.yml index 9fc2b23..35630cb 100644 --- a/tasks/action-deploy.yml +++ b/tasks/action-deploy.yml @@ -14,4 +14,5 @@ - name: start nginx using monit + sudo: yes monit: name="nginx" state=started diff --git a/tasks/action-remove-app.yml b/tasks/action-remove-app.yml index c2bb4e8..1182a1d 100644 --- a/tasks/action-remove-app.yml +++ b/tasks/action-remove-app.yml @@ -1,5 +1,6 @@ --- - name: stop app + sudo: yes monit: name="{{ app_name }}" state=stopped ignore_errors: True diff --git a/tasks/action-setup.yml b/tasks/action-setup.yml index 98dc045..a383fdf 100644 --- a/tasks/action-setup.yml +++ b/tasks/action-setup.yml @@ -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 diff --git a/tasks/common.yml b/tasks/common.yml index 2e71e8b..de0c9b6 100644 --- a/tasks/common.yml +++ b/tasks/common.yml @@ -1,5 +1,6 @@ --- - name: "install system packages" + sudo: yes apt: name="{{ item }}" update_cache=yes state=present with_items: - gcc diff --git a/tasks/deployer-user.yml b/tasks/deployer-user.yml index 8fc4a31..5122c29 100644 --- a/tasks/deployer-user.yml +++ b/tasks/deployer-user.yml @@ -1,5 +1,6 @@ --- - name: "create deployer user" + sudo: yes user: name="{{deployer}}" shell=/bin/bash @@ -9,14 +10,17 @@ - name: "create .ssh dir for deployer" + sudo: yes file: path="/home/{{ deployer }}/.ssh" state=directory - name: "copy authorized keys to deployer user" + sudo: yes shell: "echo '{{root_authorized_keys.stdout}}' > /home/{{deployer}}/.ssh/authorized_keys" - name: "chown the authorized_keys file" + sudo: yes file: path="/home/{{deployer}}/.ssh" recurse=yes mode=0700 owner="{{ deployer }}" diff --git a/tasks/monit.yml b/tasks/monit.yml index 8ef022d..b364c66 100644 --- a/tasks/monit.yml +++ b/tasks/monit.yml @@ -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" diff --git a/tasks/nginx.yml b/tasks/nginx.yml index be37c75..bf1905c 100644 --- a/tasks/nginx.yml +++ b/tasks/nginx.yml @@ -1,17 +1,21 @@ --- - 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 @@ -19,12 +23,14 @@ - 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" diff --git a/tasks/pip.yml b/tasks/pip.yml index 10ccda4..acc9819 100644 --- a/tasks/pip.yml +++ b/tasks/pip.yml @@ -4,4 +4,5 @@ - name: "install pip" + sudo: yes command: "python /tmp/get-pip.py" diff --git a/tasks/postgres.yml b/tasks/postgres.yml index cbfe4c0..657098f 100644 --- a/tasks/postgres.yml +++ b/tasks/postgres.yml @@ -1,13 +1,16 @@ --- - 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 @@ -15,6 +18,7 @@ - name: install psycopg2 python module + sudo: yes pip: name=psycopg2 diff --git a/tasks/release.yml b/tasks/release.yml index e29e67b..f805af0 100644 --- a/tasks/release.yml +++ b/tasks/release.yml @@ -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 From 244b012d5a1c0a0f15940828a3f2e0ca22746ee8 Mon Sep 17 00:00:00 2001 From: Arunvel Sriram Date: Thu, 28 Jan 2016 15:00:30 +0530 Subject: [PATCH 3/4] Use ~username for accessing home directory of users --- defaults/main.yml | 2 +- tasks/deployer-user.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 086bf99..011926f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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" diff --git a/tasks/deployer-user.yml b/tasks/deployer-user.yml index 5122c29..238df1f 100644 --- a/tasks/deployer-user.yml +++ b/tasks/deployer-user.yml @@ -11,17 +11,17 @@ - name: "create .ssh dir for deployer" sudo: yes - file: path="/home/{{ deployer }}/.ssh" state=directory + file: path="~{{ deployer }}/.ssh" state=directory - name: "copy authorized keys to deployer user" sudo: yes - shell: "echo '{{root_authorized_keys.stdout}}' > /home/{{deployer}}/.ssh/authorized_keys" + shell: "echo '{{root_authorized_keys.stdout}}' > ~{{deployer}}/.ssh/authorized_keys" - name: "chown the authorized_keys file" sudo: yes - file: path="/home/{{deployer}}/.ssh" recurse=yes mode=0700 owner="{{ deployer }}" + file: path="~{{deployer}}/.ssh" recurse=yes mode=0700 owner="{{ deployer }}" - name: "ensure projects directory" From 3d7f666d1672aeab5ca488fb789e7b2980506971 Mon Sep 17 00:00:00 2001 From: Arunvel Sriram Date: Sat, 5 Mar 2016 23:13:43 +0530 Subject: [PATCH 4/4] Updated the readme file --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d94ab8a..a870248 100644 --- a/README.md +++ b/README.md @@ -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)