File tree Expand file tree Collapse file tree 6 files changed +54
-23
lines changed
Expand file tree Collapse file tree 6 files changed +54
-23
lines changed Original file line number Diff line number Diff line change 33 hosts : nodes
44 become : yes
55 vars :
6- app_path : " {{ api_source_path | default(' /home/adminuser/ansible-setup/src/movie-analyst-api') }} "
6+ app_path : /home/adminuser/ansible-setup/src/movie-analyst-api
77
8- tasks :
8+ pre_tasks :
99 - name : Ensure curl is installed
1010 apt :
1111 name : curl
1212 state : present
1313 update_cache : true
1414
15+ - name : Disable SSH host key checking for this session
16+ set_fact :
17+ ansible_ssh_common_args : " -o StrictHostKeyChecking=no"
18+
19+ tasks :
1520 - name : Install NVM and Node.js
1621 shell : |
1722 export NVM_DIR="$HOME/.nvm"
2429 args :
2530 executable : /bin/bash
2631
32+ - name : Ensure destination directory exists
33+ file :
34+ path : " {{ app_path }}"
35+ state : directory
36+ mode : ' 0755'
37+
2738 - name : Ensure API code directory exists on jumphost
28- ansible.builtin.stat :
39+ delegate_to : localhost
40+ stat :
2941 path : " {{ app_path }}"
3042 register : api_dir
31- delegate_to : jumpbox
3243
33- - name : Fail if API code not found on jumphost
34- ansible.builtin. fail :
35- msg : " API source code not found at {{ app_path }} on jumpbox "
44+ - name : Fail if API source not found
45+ fail :
46+ msg : " API source code not found at {{ app_path }} on jumphost "
3647 when : not api_dir.stat.exists
37- delegate_to : jumpbox
3848
39- - name : Sync API source code from jumphost to target node
49+ - name : Copy API source code from jumphost to backend nodes
4050 synchronize :
4151 src : " {{ app_path }}/"
4252 dest : " {{ app_path }}/"
Original file line number Diff line number Diff line change 11#! /bin/bash
22
33# === CONFIGURACIÓN ===
4- JUMP_USER=" adminuser"
5- JUMP_HOST=" 4.154.243.88"
4+ # === STEP 0: Read JUMP_HOST and JUMP_USER from inventory ===
5+ INVENTORY_FILE=" ./ansible/inventory.ini"
6+ JUMP_HOST=$( awk ' /^\[control\]/ {getline; match($0, /ansible_host=([^ ]+)/, m); print m[1]}' " $INVENTORY_FILE " )
7+ JUMP_USER=$( awk ' /^\[control\]/ {getline; match($0, /ansible_user=([^ ]+)/, m); print m[1]}' " $INVENTORY_FILE " )
8+ if [ -z " $JUMP_USER " ] || [ -z " $JUMP_HOST " ]; then
9+ echo " ❌ Could not parse JUMP_USER or JUMP_HOST from inventory.ini"
10+ exit 1
11+ fi
12+
613SSH_KEY_LOCAL=" $HOME /.ssh/vm_ssh_key"
714REMOTE_DIR=" /home/${JUMP_USER} /ansible-setup"
815SETUP_PLAYBOOK_FILE=" setup-infra.yml"
Original file line number Diff line number Diff line change 22set -e
33
44# === CONFIG ===
5- JUMP_USER=" adminuser"
6- JUMP_HOST=" 4.154.243.88"
5+ # === STEP 0: Read JUMP_HOST and JUMP_USER from inventory ===
6+ INVENTORY_FILE=" ./ansible/inventory.ini"
7+ JUMP_HOST=$( awk ' /^\[control\]/ {getline; match($0, /ansible_host=([^ ]+)/, m); print m[1]}' " $INVENTORY_FILE " )
8+ JUMP_USER=$( awk ' /^\[control\]/ {getline; match($0, /ansible_user=([^ ]+)/, m); print m[1]}' " $INVENTORY_FILE " )
9+ if [ -z " $JUMP_USER " ] || [ -z " $JUMP_HOST " ]; then
10+ echo " ❌ Could not parse JUMP_USER or JUMP_HOST from inventory.ini"
11+ exit 1
12+ fi
13+
714SSH_KEY_LOCAL=" $HOME /.ssh/vm_ssh_key"
815REMOTE_DIR=" /home/${JUMP_USER} /ansible-setup"
916API_SRC_LOCAL=" ./src/movie-analyst-api"
Original file line number Diff line number Diff line change 11#! /bin/bash
22set -e
33
4+ # === STEP 0: Read JUMP_HOST and JUMP_USER from inventory ===
5+ INVENTORY_FILE=" ./ansible/inventory.ini"
6+ JUMP_HOST=$( awk ' /^\[control\]/ {getline; match($0, /ansible_host=([^ ]+)/, m); print m[1]}' " $INVENTORY_FILE " )
7+ JUMP_USER=$( awk ' /^\[control\]/ {getline; match($0, /ansible_user=([^ ]+)/, m); print m[1]}' " $INVENTORY_FILE " )
8+ if [ -z " $JUMP_USER " ] || [ -z " $JUMP_HOST " ]; then
9+ echo " ❌ Could not parse JUMP_USER or JUMP_HOST from inventory.ini"
10+ exit 1
11+ fi
12+
413# [0/4] Get Terraform outputs
514echo " [0/4] Getting outputs from Terraform..."
615MYSQL_HOST=$( terraform -chdir=infra output -raw mysql_fqdn)
@@ -9,8 +18,6 @@ MYSQL_PWD=$(terraform -chdir=infra output -raw mysql_admin_pwd)
918MYSQL_DB=$( terraform -chdir=infra output -raw mysql_database_name)
1019
1120# [1/4] Define SSH paths and variables
12- JUMPBOX_HOST=" 4.154.243.88"
13- JUMPBOX_USER=" adminuser"
1421SSH_KEY_LOCAL=" $HOME /.ssh/vm_ssh_key"
1522PLAYBOOK=" ansible/db-setup.yml"
1623SQL_SCRIPT=" ansible/files/mysql/movie_db.sql"
Original file line number Diff line number Diff line change 11[control]
2- jumpbox ansible_host =4.154.243.88 ansible_user =adminuser ansible_ssh_private_key_file =/home/adminuser/.ssh/vm_ssh_key
2+ jumpbox ansible_host =4.154.201.231 ansible_user =adminuser ansible_ssh_private_key_file =/home/adminuser/.ssh/vm_ssh_key
33
44[nodes]
5- epamqa-vm-api-0 ansible_host =10.0.2.6 ansible_user =adminuser ansible_ssh_private_key_file =/home/adminuser/.ssh/vm_ssh_key ansible_ssh_common_args =' -o StrictHostKeyChecking=no'
6- epamqa-vm-api-1 ansible_host =10.0.2.5 ansible_user =adminuser ansible_ssh_private_key_file =/home/adminuser/.ssh/vm_ssh_key ansible_ssh_common_args =' -o StrictHostKeyChecking=no'
5+ epamqa-vm-api-0 ansible_host =10.0.2.5 ansible_user =adminuser ansible_ssh_private_key_file =/home/adminuser/.ssh/vm_ssh_key ansible_ssh_common_args =' -o StrictHostKeyChecking=no'
6+ epamqa-vm-api-1 ansible_host =10.0.2.6 ansible_user =adminuser ansible_ssh_private_key_file =/home/adminuser/.ssh/vm_ssh_key ansible_ssh_common_args =' -o StrictHostKeyChecking=no'
77
88[mysql_server]
99epamqa-vm-api-0
@@ -13,4 +13,3 @@ epamqa-vm-api-1
1313ansible_connection =ssh
1414ansible_ssh_timeout =60
1515ansible_python_interpreter =/usr/bin/python3
16-
Original file line number Diff line number Diff line change @@ -3,14 +3,15 @@ Description=Movie Analyst API
33After=network.target
44
55[Service]
6- WorkingDirectory=/opt/movie-analyst-api
7- ExecStart=/bin/bash -c 'source /home/adminuser/.nvm/nvm.sh && nvm use 16 && node server.js'
6+ WorkingDirectory=/home/adminuser/ansible-setup/src/movie-analyst-api
7+ Environment=NODE_ENV=production
8+ Environment=PORT=8080
9+ ExecStart=/bin/bash -c 'export NVM_DIR=/home/adminuser/.nvm && source $NVM_DIR/nvm.sh && nvm use 16 && node server.js'
810Restart=always
911User=adminuser
10- Environment=NODE_ENV=production
1112StandardOutput=syslog
1213StandardError=syslog
1314SyslogIdentifier=movie-analyst-api
1415
1516[Install]
16- WantedBy=multi-user.target
17+ WantedBy=multi-user.target
You can’t perform that action at this time.
0 commit comments