Skip to content

Commit

Permalink
Merge pull request #69 from ELEVATE-Project/ansible
Browse files Browse the repository at this point in the history
Ansible
  • Loading branch information
rakeshSgr authored Oct 13, 2022
2 parents 8d1b2f6 + 693e358 commit 18350ea
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 ShikshaLokam

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 66 additions & 0 deletions deployment/ansible.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
- hosts: elevateDev
vars:
#contents: "{{ lookup('file', '/opt/rsync/text.txt') }}"
project_path: /opt/backend/deployment
tasks:
- name: Slurp hosts file
slurp:
src: /opt/backend/test/.token
register: slurpfile
#- debug: msg="{{ slurpfile['content'] | b64decode }}"
#- debug: msg="the value of foo.txt is {{ contents }}"
- name: Run vault credentials
shell: "curl --location --request GET '{{ vaultAddress }}v1/elevate/data/users' --header 'X-Vault-Token: {{ slurpfile['content'] | b64decode }}' | jq '.data' > '{{ project_path
}}/data2.json'"
register: vaultCurl
- name: Set some variable
set_fact:
release_path: "{{ project_path }}/releases/{{ lookup('pipe','date +%Y%m%d%H%M%S') }}"
current_path: "{{ project_path }}/users"
- name: Retrieve current release folder
command: readlink -f users
register: current_release_path
ignore_errors: yes
args:
chdir: "{{ project_path }}"
- name: Create new folder
file:
dest={{ release_path }}
mode=0755
recurse=yes
state=directory
- name: Clone the repository
git:
repo: https://github.com/ELEVATE-Project/user.git
dest: "{{ release_path }}"
clone: yes
update: yes
version: dev
- name: Update npm
shell: cd {{release_path}}/src && npm i

- name: Update symlink
file:
src={{ release_path }}
dest={{ current_path }}
state=link
- name: Delete old pm2 process
command: pm2 delete elevate-mentoring
ignore_errors: yes

- name: set permission
shell: chmod 744 {{ current_path }}/src/scripts/json2env.sh

- name: generate .env
shell: cat {{ project_path }}/data2.json | {{ current_path }}/src/scripts/json2env.sh > {{ current_path }}/src/.env
register: envConfig
- debug: msg=" cred {{ envConfig }} "

- name: Start pm2
command: "chdir={{current_path}}/src pm2 start app.js -i 2 --name elevate-notification"
register: pm2Info

- name: debug info
debug:
msg: "Pm2 log {{pm2Info}}"
4 changes: 4 additions & 0 deletions src/scripts/json2env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
tr -d '\n' |
grep -o '"[A-Za-z_][A-Za-z_0-9]\+"\s*:\s*\("[^"]\+"\|[0-9\.]\+\|true\|false\|null\)' |
sed 's/"\(.*\)"\s*:\s*"\?\([^"]\+\)"\?/\1="\2"/'

0 comments on commit 18350ea

Please sign in to comment.