Skip to content

Commit 15556bc

Browse files
committed
copy source files to ansible folder
1 parent c36011f commit 15556bc

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

ansible/api-setup.yml

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,34 @@
11
---
2-
- name: Deploy Node.js Movie Analyst API
3-
hosts: mysql_server
2+
- name: Setup and Deploy Node.js API
3+
hosts: nodes
44
become: yes
5-
65
vars:
7-
node_version: "16"
8-
api_source_path: "/home/adminuser/ansible-setup/src"
9-
service_name: "mysqlmovie-api"
10-
systemd_template: "/home/adminuser/ansible-setup/templates/movie-api.service.j2"
6+
app_path: /home/adminuser/ansible-setup/src/movie-analyst-api
117

128
tasks:
13-
- name: Ensure Node.js is installed (via NVM)
9+
- name: Ensure curl is installed
10+
apt:
11+
name: curl
12+
state: present
13+
update_cache: true
14+
15+
- name: Install NVM and Node.js
1416
shell: |
15-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
1617
export NVM_DIR="$HOME/.nvm"
18+
if [ ! -d "$NVM_DIR" ]; then
19+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
20+
fi
1721
source "$NVM_DIR/nvm.sh"
18-
nvm install {{ node_version }}
19-
nvm alias default {{ node_version }}
22+
nvm install 16
23+
nvm alias default 16
2024
args:
2125
executable: /bin/bash
2226

2327
- name: Install app dependencies
2428
shell: |
2529
export NVM_DIR="$HOME/.nvm"
2630
source "$NVM_DIR/nvm.sh"
27-
cd {{ api_source_path }}
31+
cd {{ app_path }}
2832
npm install
2933
args:
3034
executable: /bin/bash
31-
32-
- name: Copy systemd service unit file
33-
template:
34-
src: "{{ systemd_template }}"
35-
dest: "/etc/systemd/system/{{ service_name }}.service"
36-
mode: "0644"
37-
38-
- name: Reload systemd
39-
systemd:
40-
daemon_reload: yes
41-
42-
- name: Enable and start the API service
43-
systemd:
44-
name: "{{ service_name }}"
45-
state: restarted
46-
enabled: yes

ansible/deploy-api-from-local.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ INVENTORY_LOCAL="./ansible/inventory.ini"
1515
INVENTORY_REMOTE="${REMOTE_DIR}/inventory.ini"
1616

1717
# === STEP 1: Upload playbook and inventory ===
18-
echo "[1/3] Uploading playbook and inventory..."
18+
echo "[1/4] Uploading playbook and inventory..."
1919
scp -i "${SSH_KEY_LOCAL}" "${API_PLAYBOOK_LOCAL}" "${INVENTORY_LOCAL}" "${JUMP_USER}@${JUMP_HOST}:${REMOTE_DIR}/"
2020

21+
echo "[2/4] Copiando código fuente de la API..."
22+
scp -i "$SSH_KEY_LOCAL" -r ./src/movie-analyst-api "$JUMPBOX_USER@$JUMPBOX_HOST:/home/$JUMPBOX_USER/ansible-setup/src"
23+
2124
# === STEP 2: Upload systemd template ===
22-
echo "[2/3] Uploading systemd template..."
25+
echo "[3/4] Uploading systemd template..."
2326
ssh -i "${SSH_KEY_LOCAL}" "${JUMP_USER}@${JUMP_HOST}" "mkdir -p ${REMOTE_DIR}/templates"
2427
scp -i "${SSH_KEY_LOCAL}" "${TEMPLATE_LOCAL}" "${JUMP_USER}@${JUMP_HOST}:${TEMPLATE_REMOTE}"
2528

2629
# === STEP 3: Execute playbook remotely ===
27-
echo "[3/3] Executing playbook from the jump host..."
30+
echo "[4/4] Executing playbook from the jump host..."
2831
ssh -i "${SSH_KEY_LOCAL}" "${JUMP_USER}@${JUMP_HOST}" << EOF
2932
set -e
3033
cd "${REMOTE_DIR}"

0 commit comments

Comments
 (0)