Refactor SSH key scanning and connection in Ansible actions

This commit is contained in:
2024-10-06 14:37:58 +02:00
parent b0a0e4ea4d
commit f235dea2af
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -56,7 +56,7 @@ runs:
run: | run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
for HOST in $(cat /tmp/ansible_hosts); do for HOST in $(cat /tmp/ansible_hosts); do
ssh-keyscan $HOST >> ~/.ssh/known_hosts ssh-keyscan "$HOST" >> ~/.ssh/known_hosts
done done
chmod 600 ~/.ssh/known_hosts chmod 600 ~/.ssh/known_hosts
@@ -87,5 +87,5 @@ runs:
SSH_AUTH_SOCK: ${{ inputs.ssh-auth-socket }} SSH_AUTH_SOCK: ${{ inputs.ssh-auth-socket }}
run: | run: |
for HOST in $(cat /tmp/ansible_hosts); do for HOST in $(cat /tmp/ansible_hosts); do
ssh $ANSIBLE_USER@$HOST echo "SSH connection to $HOST successful" ssh "$ANSIBLE_USER@$HOST" echo "SSH connection to "$HOST" successful"
done done
+1 -1
View File
@@ -41,7 +41,7 @@ runs:
IP_ADDR=$(ansible -i inventory/hosts -u $ANSIBLE_USER -m shell -a "curl -s ifconfig.me" $K8S_TARGET | grep -oP '(\d+\.){3}\d+') IP_ADDR=$(ansible -i inventory/hosts -u $ANSIBLE_USER -m shell -a "curl -s ifconfig.me" $K8S_TARGET | grep -oP '(\d+\.){3}\d+')
# Forward the k8s API server port to localhost # Forward the k8s API server port to localhost
ssh -f -N -L 16443:localhost:16443 $ANSIBLE_USER@$ANSIBLE_HOST ssh -f -N -L 16443:localhost:16443 "$ANSIBLE_USER@$ANSIBLE_HOST"
# Override the kube config file to use localhost # Override the kube config file to use localhost
sed -i "s/server: https:\/\/$IP_ADDR:16443/server: https:\/\/localhost:16443/g" ~/.kube/config sed -i "s/server: https:\/\/$IP_ADDR:16443/server: https:\/\/localhost:16443/g" ~/.kube/config