From c8e82cbab54c0aab85d4e08bd8b3cd0953216f87 Mon Sep 17 00:00:00 2001 From: Alexandre Pires Date: Sun, 6 Oct 2024 14:44:22 +0200 Subject: [PATCH] Refactor Ansible actions to improve host inventory handling --- .github/actions/setup-ansible-env/action.yml | 2 +- .github/actions/setup-k8s-env/action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-ansible-env/action.yml b/.github/actions/setup-ansible-env/action.yml index 74161f1..c8597d3 100644 --- a/.github/actions/setup-ansible-env/action.yml +++ b/.github/actions/setup-ansible-env/action.yml @@ -48,7 +48,7 @@ runs: env: HOST_GROUP: ${{ inputs.host-group }} run: | - ansible-inventory -i inventory/hosts --list --yaml $HOST_GROUP | grep -oP '(\w+\.){2}\w+' | sort -u > /tmp/ansible_hosts + ansible-inventory -i inventory/hosts --list --yaml $HOST_GROUP | grep -oP '([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}' | sort -u > /tmp/ansible_hosts echo "hosts=$(cat /tmp/ansible_hosts)" >> $GITHUB_OUTPUT - name: Read SSH host keys from remote hosts diff --git a/.github/actions/setup-k8s-env/action.yml b/.github/actions/setup-k8s-env/action.yml index 8055eb3..ff8093b 100644 --- a/.github/actions/setup-k8s-env/action.yml +++ b/.github/actions/setup-k8s-env/action.yml @@ -37,7 +37,7 @@ runs: K8S_TARGET: ${{ inputs.k8s-target }} run: | # Get Hostname and IP address of the target - ANSIBLE_HOST=$(ansible -i inventory/hosts -u $ANSIBLE_USER -m shell -a "hostname" $K8S_TARGET | grep -oP '(\w+\.){2}\w+' | head -1) + ANSIBLE_HOST=$(ansible -i inventory/hosts -u $ANSIBLE_USER -m shell -a "hostname" $K8S_TARGET | grep -oP '([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}' | head -1) 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