Refactor Ansible actions to improve host inventory handling

This commit is contained in:
2024-10-06 14:44:22 +02:00
parent f235dea2af
commit c8e82cbab5
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ runs:
env: env:
HOST_GROUP: ${{ inputs.host-group }} HOST_GROUP: ${{ inputs.host-group }}
run: | 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 echo "hosts=$(cat /tmp/ansible_hosts)" >> $GITHUB_OUTPUT
- name: Read SSH host keys from remote hosts - name: Read SSH host keys from remote hosts
+1 -1
View File
@@ -37,7 +37,7 @@ runs:
K8S_TARGET: ${{ inputs.k8s-target }} K8S_TARGET: ${{ inputs.k8s-target }}
run: | run: |
# Get Hostname and IP address of the target # 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+') 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