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) 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/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 < /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" 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