From f235dea2af269e6199d99548ad1b4584de62f49f Mon Sep 17 00:00:00 2001 From: Alexandre Pires Date: Sun, 6 Oct 2024 14:37:58 +0200 Subject: [PATCH] Refactor SSH key scanning and connection in Ansible actions --- .github/actions/setup-ansible-env/action.yml | 4 ++-- .github/actions/setup-k8s-env/action.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup-ansible-env/action.yml b/.github/actions/setup-ansible-env/action.yml index daeac05..74161f1 100644 --- a/.github/actions/setup-ansible-env/action.yml +++ b/.github/actions/setup-ansible-env/action.yml @@ -56,7 +56,7 @@ runs: run: | mkdir -p ~/.ssh for HOST in $(cat /tmp/ansible_hosts); do - ssh-keyscan $HOST >> ~/.ssh/known_hosts + ssh-keyscan "$HOST" >> ~/.ssh/known_hosts done chmod 600 ~/.ssh/known_hosts @@ -87,5 +87,5 @@ runs: SSH_AUTH_SOCK: ${{ inputs.ssh-auth-socket }} run: | 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 diff --git a/.github/actions/setup-k8s-env/action.yml b/.github/actions/setup-k8s-env/action.yml index f244779..8055eb3 100644 --- a/.github/actions/setup-k8s-env/action.yml +++ b/.github/actions/setup-k8s-env/action.yml @@ -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+') # 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 sed -i "s/server: https:\/\/$IP_ADDR:16443/server: https:\/\/localhost:16443/g" ~/.kube/config