mirror of
https://github.com/Expand-sys/DEPLOYCCASH
synced 2025-12-15 13:32:15 +11:00
220 lines
6.5 KiB
YAML
220 lines
6.5 KiB
YAML
---
|
|
- hosts: all
|
|
name: DeployCCash
|
|
vars:
|
|
become: true
|
|
pre_tasks:
|
|
- name: Load variables
|
|
ansible.builtin.include_vars: '{{ item }}'
|
|
with_first_found:
|
|
- "vars/default.yml"
|
|
|
|
tasks:
|
|
- name: Add repository
|
|
ansible.builtin.yum:
|
|
name: epel-release
|
|
state: present
|
|
when: ansible_os_family == "RedHat"
|
|
|
|
- name: Install dependencies
|
|
ansible.builtin.yum:
|
|
name: [git, gcc, gcc-c++, libuuid-devel, openssl-devel, zlib-devel, jsoncpp-devel, cmake]
|
|
state: present
|
|
when: ansible_os_family == "RedHat"
|
|
|
|
- name: Clone CCash repository
|
|
ansible.builtin.git:
|
|
repo: https://github.com/EntireTwix/CCash.git
|
|
dest: '{{ BUILD_DIR }}/CCash'
|
|
recursive: true
|
|
update: true
|
|
force: true
|
|
version: "{{ BRANCH }}"
|
|
|
|
- name: Make lib base64
|
|
community.general.make:
|
|
chdir: '{{ BUILD_DIR }}/CCash/third_party/base64'
|
|
params:
|
|
AVX2_CFLAGS: -mavx2
|
|
SSSE3_CFLAGS: -mssse3
|
|
SSE41_CFLAGS: -msse4.1
|
|
SSE42_CFLAGS: -msse4.2
|
|
AVX_CFLAGS: -mavx
|
|
|
|
- name: Create build dir
|
|
ansible.builtin.file:
|
|
path: '{{ BUILD_DIR }}/CCash/build'
|
|
state: directory
|
|
mode: 0700
|
|
|
|
- name: Cmake CCash
|
|
ansible.builtin.command:
|
|
chdir: '{{ BUILD_DIR }}/CCash/build'
|
|
cmd: |
|
|
cmake -DDROGON_CONFIG_LOC="{{ BUILD_DIR }}/CCash/config/config.json" \
|
|
-DUSER_SAVE_LOC="{{ BUILD_DIR }}/CCash/config/users.dat" \
|
|
-DUSE_DEPRECATED_ENDPOINTS="{{ USE_DEPRECATED_ENDPOINTS }}" ..
|
|
# needs changes argument
|
|
|
|
- name: Make CCash
|
|
community.general.make:
|
|
chdir: '{{ BUILD_DIR }}/CCash/build'
|
|
params:
|
|
NUM_THREADS: '-j{{ ansible_processor_vcpus }}'
|
|
|
|
- name: Create users file
|
|
ansible.builtin.command:
|
|
chdir: '{{ BUILD_DIR }}/CCash/build/'
|
|
cmd: ./bank
|
|
creates: '{{ BUILD_DIR }}/CCash/config/users.dat'
|
|
|
|
- name: Chmod +x ssl.sh
|
|
ansible.builtin.file:
|
|
mode: u+x
|
|
path: '{{ BUILD_DIR }}/CCash/config/ssl.sh'
|
|
|
|
- name: Create ssl gen file
|
|
ansible.builtin.copy:
|
|
content: |
|
|
{
|
|
"listeners": [
|
|
{
|
|
"address": "0.0.0.0",
|
|
"port": {{ CCASH_PORT }},
|
|
"https": false
|
|
},
|
|
{
|
|
"address": "0.0.0.0",
|
|
"port": {{ CCASH_PORT_S }},
|
|
"https": true,
|
|
"cert": "{{ BUILD_DIR }}/CCash/config/cert.cert",
|
|
"key": "{{ BUILD_DIR }}/CCash/config/key.key"
|
|
}
|
|
]
|
|
}
|
|
dest: "{{ BUILD_DIR }}/CCash/config/config.json"
|
|
mode: 0700
|
|
|
|
|
|
- name: Create ssl gen file
|
|
ansible.builtin.copy:
|
|
content: |
|
|
#!/bin/bash
|
|
|
|
|
|
openssl genrsa -out server.pass.key 2048
|
|
openssl rsa -in server.pass.key -out {{ BUILD_DIR }}/CCash/config/key.key
|
|
rm server.pass.key
|
|
openssl req -new -key {{ BUILD_DIR }}/CCash/config/key.key -out server.csr \
|
|
-subj "/C=US/ST=CCashland/L=NEW CCASH/O=CCash/OU=Devs/CN=localhost"
|
|
openssl x509 -req -days 365 -in server.csr -signkey {{ BUILD_DIR }}/CCash/config/key.key -out {{ BUILD_DIR }}/CCash/config/cert.cert
|
|
dest: "{{ BUILD_DIR }}/CCash/config/ssl.sh"
|
|
mode: 0700
|
|
|
|
- name: Generate default ssl
|
|
ansible.builtin.command:
|
|
chdir: '{{ BUILD_DIR }}/CCash/config/'
|
|
cmd: './ssl.sh'
|
|
creates: '{{ BUILD_DIR }}/CCash/config/cert.cert'
|
|
|
|
- name: Start CCash Api Server
|
|
ansible.builtin.command:
|
|
chdir: '{{ BUILD_DIR }}/CCash/build'
|
|
cmd: './bank {{ ADMIN_A }} {{ SAVE_FREQ }} true'
|
|
when: START_SERVICES == true
|
|
|
|
- name: Clone Web
|
|
ansible.builtin.git:
|
|
repo: https://github.com/Expand-sys/ccashfrontend.git
|
|
dest: '{{ BUILD_DIR }}/CCash/web'
|
|
update: true
|
|
force: true
|
|
when: WEB_ENABLED == true
|
|
|
|
- name: "Install Nodejs 18 module"
|
|
ansible.builtin.command: dnf module install -y nodejs:18/common
|
|
register: result
|
|
changed_when:
|
|
- '"Enabling module streams" in result.stdout'
|
|
when: ansible_os_family == "RedHat" and WEB_ENABLED == true
|
|
|
|
- name: Install pm2
|
|
community.general.npm:
|
|
path: '{{ BUILD_DIR }}/CCash/web'
|
|
name: pm2
|
|
global: true
|
|
when: WEB_ENABLED == true
|
|
|
|
- name: Install web dependencies
|
|
community.general.npm:
|
|
path: '{{ BUILD_DIR }}/CCash/web'
|
|
when: WEB_ENABLED == true
|
|
|
|
- name: Create .env file
|
|
ansible.builtin.copy:
|
|
content: |
|
|
BANKAPIURL=http://127.0.0.1:{{ CCASH_PORT }}
|
|
SECURE=true
|
|
SETUP=true
|
|
PORT={{ WEB_PORT }}
|
|
dest: '{{ BUILD_DIR }}/CCash/web/.env'
|
|
mode: 0700
|
|
when: WEB_ENABLED == true
|
|
|
|
- name: Create pm2 file
|
|
ansible.builtin.copy:
|
|
content: |
|
|
{
|
|
"name": "ccashfrontend",
|
|
"script": "{{ BUILD_DIR }}/ccash/web/index.js",
|
|
"watch": "{{ BUILD_DIR }}/ccash/web/tmp/restart.txt",
|
|
"instances": "1"
|
|
}
|
|
dest: "{{ BUILD_DIR }}/CCash/web/pm2.json"
|
|
mode: 0700
|
|
when: WEB_ENABLED == true
|
|
|
|
|
|
- name: Start webapp service
|
|
ansible.builtin.command:
|
|
chdir: "{{ BUILD_DIR }}/CCash/web"
|
|
cmd: |
|
|
pm2 start index.js --update-env --name 'CCashFrontend' -f
|
|
when: START_SERVICES == true and WEB_ENABLED == true
|
|
|
|
- name: Enable web app on boot
|
|
ansible.builtin.command:
|
|
chdir: "{{ BUILD_DIR }}/CCash/web"
|
|
cmd: |
|
|
pm2 startup
|
|
when: START_ON_BOOT == true and START_SERVICES == true and WEB_ENABLED == true
|
|
|
|
- name: Enable ccash on boot
|
|
ansible.builtin.cron:
|
|
name: CCash enable on boot
|
|
special_time: reboot
|
|
state: present
|
|
job: '{{ BUILD_DIR }}/CCash/build/bank {{ ADMIN_A }} {{ SAVE_FREQ }} true'
|
|
when: START_ON_BOOT == true
|
|
|
|
- name: Allow firewalld ports
|
|
ansible.posix.firewalld:
|
|
permanent: true
|
|
port: '{{ CCASH_PORT }}/tcp'
|
|
state: enabled
|
|
- name: Allow firewalld ports
|
|
ansible.posix.firewalld:
|
|
permanent: true
|
|
port: '{{ CCASH_PORT_S }}/tcp'
|
|
state: enabled
|
|
|
|
- name: Allow firewalld ports
|
|
ansible.posix.firewalld:
|
|
permanent: true
|
|
port: 3000/tcp
|
|
state: enabled
|
|
when: WEB_ENABLED == true
|
|
|
|
- name: reload firewalld
|
|
ansible.builtin.command:
|
|
cmd: "firewall-cmd --reload"
|