Spaces:
No application file
No application file
Jacob Molnia
commited on
Commit
•
82a2f16
1
Parent(s):
53b59a6
intermidate setup5/maybe done2
Browse files
deployment/02_deploy_to_controller/playbooks/connection_check_setup.yml
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
vars:
|
6 |
repo_dest: '/opt/CS_553'
|
7 |
vars_files:
|
8 |
-
- vars/secrets.yml
|
9 |
tasks:
|
10 |
- name: Create connection check script
|
11 |
template:
|
|
|
5 |
vars:
|
6 |
repo_dest: '/opt/CS_553'
|
7 |
vars_files:
|
8 |
+
- ../vars/secrets.yml
|
9 |
tasks:
|
10 |
- name: Create connection check script
|
11 |
template:
|
deployment/02_deploy_to_controller/playbooks/initial_setup.yml
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
hosts: all
|
4 |
become: yes
|
5 |
vars_files:
|
6 |
-
- vars/secrets.yml
|
7 |
vars:
|
8 |
repo_dest: '/opt/CS_553'
|
9 |
tasks:
|
|
|
3 |
hosts: all
|
4 |
become: yes
|
5 |
vars_files:
|
6 |
+
- ../vars/secrets.yml
|
7 |
vars:
|
8 |
repo_dest: '/opt/CS_553'
|
9 |
tasks:
|
deployment/02_deploy_to_controller/templates/connection_check.sh.j2
CHANGED
@@ -4,23 +4,35 @@
|
|
4 |
APP_SERVER="student-admin@group18"
|
5 |
INITIAL_SETUP_SCRIPT="/opt/CS_553/deployment/02_deploy_to_controller/scripts/initial_ssh_config.sh"
|
6 |
TAILSCALE_KEY_FILE="/home/ubuntu/.tailscale_key"
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# Function to check SSH connection
|
9 |
check_ssh_connection() {
|
10 |
-
|
11 |
-
|
12 |
}
|
13 |
|
14 |
# Main logic
|
15 |
if ! check_ssh_connection; then
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
else
|
21 |
-
|
22 |
-
|
23 |
fi
|
|
|
|
|
|
|
|
|
24 |
else
|
25 |
-
|
26 |
fi
|
|
|
4 |
APP_SERVER="student-admin@group18"
|
5 |
INITIAL_SETUP_SCRIPT="/opt/CS_553/deployment/02_deploy_to_controller/scripts/initial_ssh_config.sh"
|
6 |
TAILSCALE_KEY_FILE="/home/ubuntu/.tailscale_key"
|
7 |
+
ANSIBLE_PLAYBOOK="/opt/CS_553/deployment/01_deploy_to_app/playbooks/main.yml"
|
8 |
+
ANSIBLE_INVENTORY="/opt/CS_553/deployment/01_deploy_to_app/inventory/hosts.ini"
|
9 |
+
ANSIBLE_CONFIG="/opt/CS_553/deployment/01_deploy_to_app/ansible.cfg"
|
10 |
+
VAULT_PASSWORD_FILE="/home/ubuntu/.ansible/vault_password.txt"
|
11 |
|
12 |
# Function to check SSH connection
|
13 |
check_ssh_connection() {
|
14 |
+
ssh -o BatchMode=yes -o ConnectTimeout=5 $APP_SERVER exit
|
15 |
+
return $?
|
16 |
}
|
17 |
|
18 |
# Main logic
|
19 |
if ! check_ssh_connection; then
|
20 |
+
echo "Connection failed. Running initial setup script and 01 ansible script..."
|
21 |
+
if [ -f "$TAILSCALE_KEY_FILE" ]; then
|
22 |
+
TAILSCALE_KEY=$(cat "$TAILSCALE_KEY_FILE")
|
23 |
+
$INITIAL_SETUP_SCRIPT -k "$TAILSCALE_KEY"
|
24 |
+
|
25 |
+
# Run the 01 ansible script
|
26 |
+
if [ -f "$ANSIBLE_PLAYBOOK" ] && [ -f "$ANSIBLE_INVENTORY" ] && [ -f "$ANSIBLE_CONFIG" ] && [ -f "$VAULT_PASSWORD_FILE" ]; then
|
27 |
+
ANSIBLE_CONFIG="$ANSIBLE_CONFIG" ansible-playbook -i "$ANSIBLE_INVENTORY" "$ANSIBLE_PLAYBOOK" --vault-password-file "$VAULT_PASSWORD_FILE"
|
28 |
else
|
29 |
+
echo "One or more required files for running the ansible playbook are missing."
|
30 |
+
exit 1
|
31 |
fi
|
32 |
+
else
|
33 |
+
echo "Tailscale key file not found. Cannot run initial setup or ansible playbook."
|
34 |
+
exit 1
|
35 |
+
fi
|
36 |
else
|
37 |
+
echo "Connection successful. No action needed."
|
38 |
fi
|