Refactor file path and update workflow name in actions-validate.yml

Add setup-terraform-env action.yml
Update setup-k8s-env action.yml with ssh-auth-sock input
This commit is contained in:
2024-09-30 22:25:55 +02:00
parent adfff953e7
commit c1d8d67cbc
4 changed files with 49 additions and 21 deletions
+26 -12
View File
@@ -7,13 +7,19 @@ inputs:
ansible-user:
description: "The user to use for Ansible"
required: true
trusted-hosts:
description: "The list of trusted hosts"
required: true
ssh-auth-socket:
description: "The SSH_AUTH_SOCK environment variable"
default: "/tmp/ssh_agent.sock"
host-group:
description: "The host group to setup the Ansible environment"
default: "all"
outputs:
ssh-auth-sock:
description: "The SSH_AUTH_SOCK environment variable"
value: ${{ steps.start-ssh-agent.outputs.ssh-auth-sock }}
hosts:
description: "The list of hosts in the host group"
value: ${{ steps.read-hosts.outputs.hosts }}
runs:
using: "composite"
@@ -25,7 +31,7 @@ runs:
sudo apt-get install -y python3-pip
python3 -m pip install -r requirements.txt
- name: Setup SSH Key
- name: Prepare SSH key
shell: bash
env:
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
@@ -36,13 +42,20 @@ runs:
cp ssh-keys/ansible/id_ecdsa ~/.ssh/id_ecdsa
chmod 600 ~/.ssh/id_ecdsa
- name: Read SSH Trusted Hosts keys
- name: Read hosts from inventory
id: read-hosts
shell: bash
env:
TRUSTED_HOSTS: ${{ inputs.trusted-hosts }}
HOST_GROUP: ${{ inputs.host-group }}
run: |
ansible-inventory ansible-inventory --list --yaml $HOST_GROUP | grep -oP '(\w+\.){2}\w+' | sort -u > /tmp/ansible_hosts
echo "::set-output name=hosts::$(cat /tmp/ansible_hosts)"
- name: Read SSH host keys from remote hosts
shell: bash
run: |
mkdir -p ~/.ssh
for HOST in $TRUSTED_HOSTS; do
for HOST in $(cat /tmp/ansible_hosts); do
ssh-keyscan $HOST >> ~/.ssh/known_hosts
done
chmod 600 ~/.ssh/known_hosts
@@ -54,24 +67,25 @@ runs:
echo " HostKeyAlgorithms +sk-ecdsa-sha2-nistp256@openssh.com, sk-ssh-ed25519@openssh.com"
chmod 600 ~/.ssh/config
- name: Start SSH Agent
- name: Start SSH agent and add SSH key
id: start-ssh-agent
shell: bash
env:
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
SSH_AUTH_SOCK: ${{ inputs.ssh-auth-socket }}
run: |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
echo 'sectool vault get SSH_PASSWORD' > ~/.ssh_askpass && chmod +x ~/.ssh_askpass
DISPLAY=None SSH_ASKPASS=~/.ssh_askpass ssh-add ~/.ssh/id_ecdsa < /dev/null
rm ~/.ssh_askpass
echo "::set-output name=ssh-auth-sock::$SSH_AUTH_SOCK"
- name: Check SSH Connection to remote hosts
shell: bash
env:
TRUSTED_HOSTS: ${{ inputs.trusted-hosts }}
ANSIBLE_USER: ${{ inputs.ansible-user }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
SSH_AUTH_SOCK: ${{ inputs.ssh-auth-socket }}
run: |
for HOST in $TRUSTED_HOSTS; do
for HOST in $(cat /tmp/ansible_hosts); do
ssh $ANSIBLE_USER@$HOST echo "SSH connection to $HOST successful"
done
+5 -2
View File
@@ -10,6 +10,9 @@ inputs:
k8s-target:
description: "The target host to deploy the K8S applications"
default: "microk8s"
ssh-auth-sock:
description: "The SSH_AUTH_SOCK environment variable"
default: "/tmp/ssh_agent.sock"
runs:
using: "composite"
@@ -19,7 +22,7 @@ runs:
env:
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
ANSIBLE_USER: ${{ inputs.ansible-user }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
SSH_AUTH_SOCK: ${{ inputs.ssh-auth-sock }}
K8S_TARGET: ${{ inputs.k8s-target }}
run: |
mkdir -p ~/.kube
@@ -30,7 +33,7 @@ runs:
env:
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
ANSIBLE_USER: ${{ inputs.ansible-user }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
SSH_AUTH_SOCK: ${{ inputs.ssh-auth-sock }}
K8S_TARGET: ${{ inputs.k8s-target }}
run: |
# Get Hostname and IP address of the target
@@ -0,0 +1,10 @@
name: Setup Terraform Environment
description: Prepare the environment for A13labs CI/CD pipelines
runs:
using: "composite"
steps:
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.9.6