This commit is contained in:
Kris Lamoureux 2024-05-03 02:36:42 -04:00
parent 8d1cc8e160
commit 3f65c92ba8
3 changed files with 18 additions and 27 deletions

View File

@ -13,6 +13,12 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
with:
detached: true
limit-access-to-actor: true
- name: Cache Vagrant boxes - name: Cache Vagrant boxes
uses: actions/cache@v3 uses: actions/cache@v3
with: with:

2
Vagrantfile vendored
View File

@ -44,6 +44,6 @@ Vagrant.configure("2") do |config|
ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles" ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles"
ansible.compatibility_mode = "2.0" ansible.compatibility_mode = "2.0"
ansible.playbook = "dev/" + PLAYBOOK + ".yml" ansible.playbook = "dev/" + PLAYBOOK + ".yml"
ansible.raw_arguments = ["--diff", "-vvv"] ansible.raw_arguments = ["--diff", "-vvvv"]
end end
end end

View File

@ -9,7 +9,7 @@ SSH_AVAILABLE=0
DEBUG_ID="[homelab-ci]" DEBUG_ID="[homelab-ci]"
# Run Vagrant Up in the background # Run Vagrant Up in the background
PLAYBOOK=dockerbox vagrant up --debug & PLAYBOOK=dockerbox vagrant up &
VAGRANT_UP_PID=$! VAGRANT_UP_PID=$!
# Initial delay # Initial delay
@ -18,33 +18,18 @@ sleep $INITIAL_SLEEP
# Loop until timeout or breaks # Loop until timeout or breaks
while [[ $ELAPSED -lt $TIMEOUT ]]; do while [[ $ELAPSED -lt $TIMEOUT ]]; do
VAGRANT_SSH_CONFIG=$(mktemp)
vagrant ssh-config > "$VAGRANT_SSH_CONFIG"
echo "$DEBUG_ID SSH config at $VAGRANT_SSH_CONFIG"
cat "$VAGRANT_SSH_CONFIG"
echo "$DEBUG_ID Vagrant status"
vagrant status vagrant status
PRIVATE_KEY="$(vagrant ssh-config | grep -vE 'IdentityFile.*\.rsa$' | awk '{print $2}')"
HOST_IP="$(vagrant ssh-config | grep HostName | awk '{print $2}')"
echo "$DEBUG_ID Checking SSH connection availability..." # SSH attempt
echo "$DEBUG_ID Private Key: $PRIVATE_KEY"
echo "$DEBUG_ID Host IP: $HOST_IP"
echo "$DEBUG_ID Running nmap to check open ports..."
# Check if SSH is open
nmap -p 22 "$HOST_IP" | grep "22/tcp open" && SSH_AVAILABLE=1 || SSH_AVAILABLE=0
if [[ $SSH_AVAILABLE -eq 1 ]]; then
echo "$DEBUG_ID SSH port is open, attempting connection..."
set -x set -x
ssh -vvv -i "$PRIVATE_KEY" \ ssh -vvv -F "$VAGRANT_SSH_CONFIG" default 'cat /etc/os-release' && set +x; break \
-o UserKnownHostsFile=/dev/null \ || echo "$DEBUG_ID SSH connection failed, retrying in $SLEEP_DURATION seconds..."
-o StrictHostKeyChecking=no \
-o IdentitiesOnly=yes \
-o PreferredAuthentications=publickey \
-o PubkeyAuthentication=yes \
-o PasswordAuthentication=no \
-o KbdInteractiveAuthentication=no \
vagrant@"$HOST_IP" cat /etc/os-release && break || echo "$DEBUG_ID SSH connection failed, retrying..."
set +x set +x
else
echo "$DEBUG_ID SSH port not open, retrying in $SLEEP_DURATION seconds..."
fi
# Sleep and start again # Sleep and start again
sleep $SLEEP_DURATION sleep $SLEEP_DURATION