Skip to content
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

Ansible #69

Merged
merged 4 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
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
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"/'