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:
@@ -7,13 +7,19 @@ inputs:
|
|||||||
ansible-user:
|
ansible-user:
|
||||||
description: "The user to use for Ansible"
|
description: "The user to use for Ansible"
|
||||||
required: true
|
required: true
|
||||||
trusted-hosts:
|
ssh-auth-socket:
|
||||||
description: "The list of trusted hosts"
|
description: "The SSH_AUTH_SOCK environment variable"
|
||||||
required: true
|
default: "/tmp/ssh_agent.sock"
|
||||||
|
host-group:
|
||||||
|
description: "The host group to setup the Ansible environment"
|
||||||
|
default: "all"
|
||||||
outputs:
|
outputs:
|
||||||
ssh-auth-sock:
|
ssh-auth-sock:
|
||||||
description: "The SSH_AUTH_SOCK environment variable"
|
description: "The SSH_AUTH_SOCK environment variable"
|
||||||
value: ${{ steps.start-ssh-agent.outputs.ssh-auth-sock }}
|
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:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
@@ -25,7 +31,7 @@ runs:
|
|||||||
sudo apt-get install -y python3-pip
|
sudo apt-get install -y python3-pip
|
||||||
python3 -m pip install -r requirements.txt
|
python3 -m pip install -r requirements.txt
|
||||||
|
|
||||||
- name: Setup SSH Key
|
- name: Prepare SSH key
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
|
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
|
||||||
@@ -36,13 +42,20 @@ runs:
|
|||||||
cp ssh-keys/ansible/id_ecdsa ~/.ssh/id_ecdsa
|
cp ssh-keys/ansible/id_ecdsa ~/.ssh/id_ecdsa
|
||||||
chmod 600 ~/.ssh/id_ecdsa
|
chmod 600 ~/.ssh/id_ecdsa
|
||||||
|
|
||||||
- name: Read SSH Trusted Hosts keys
|
- name: Read hosts from inventory
|
||||||
|
id: read-hosts
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
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: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
for HOST in $TRUSTED_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
|
||||||
@@ -54,24 +67,25 @@ runs:
|
|||||||
echo " HostKeyAlgorithms +sk-ecdsa-sha2-nistp256@openssh.com, sk-ssh-ed25519@openssh.com"
|
echo " HostKeyAlgorithms +sk-ecdsa-sha2-nistp256@openssh.com, sk-ssh-ed25519@openssh.com"
|
||||||
chmod 600 ~/.ssh/config
|
chmod 600 ~/.ssh/config
|
||||||
|
|
||||||
- name: Start SSH Agent
|
- name: Start SSH agent and add SSH key
|
||||||
|
id: start-ssh-agent
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
|
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
|
||||||
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
|
SSH_AUTH_SOCK: ${{ inputs.ssh-auth-socket }}
|
||||||
run: |
|
run: |
|
||||||
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
|
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
|
||||||
echo 'sectool vault get SSH_PASSWORD' > ~/.ssh_askpass && chmod +x ~/.ssh_askpass
|
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
|
DISPLAY=None SSH_ASKPASS=~/.ssh_askpass ssh-add ~/.ssh/id_ecdsa < /dev/null
|
||||||
rm ~/.ssh_askpass
|
rm ~/.ssh_askpass
|
||||||
|
echo "::set-output name=ssh-auth-sock::$SSH_AUTH_SOCK"
|
||||||
|
|
||||||
- name: Check SSH Connection to remote hosts
|
- name: Check SSH Connection to remote hosts
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
TRUSTED_HOSTS: ${{ inputs.trusted-hosts }}
|
|
||||||
ANSIBLE_USER: ${{ inputs.ansible-user }}
|
ANSIBLE_USER: ${{ inputs.ansible-user }}
|
||||||
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
|
SSH_AUTH_SOCK: ${{ inputs.ssh-auth-socket }}
|
||||||
run: |
|
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"
|
ssh $ANSIBLE_USER@$HOST echo "SSH connection to $HOST successful"
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ inputs:
|
|||||||
k8s-target:
|
k8s-target:
|
||||||
description: "The target host to deploy the K8S applications"
|
description: "The target host to deploy the K8S applications"
|
||||||
default: "microk8s"
|
default: "microk8s"
|
||||||
|
ssh-auth-sock:
|
||||||
|
description: "The SSH_AUTH_SOCK environment variable"
|
||||||
|
default: "/tmp/ssh_agent.sock"
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
@@ -19,7 +22,7 @@ runs:
|
|||||||
env:
|
env:
|
||||||
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
|
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
|
||||||
ANSIBLE_USER: ${{ inputs.ansible-user }}
|
ANSIBLE_USER: ${{ inputs.ansible-user }}
|
||||||
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
|
SSH_AUTH_SOCK: ${{ inputs.ssh-auth-sock }}
|
||||||
K8S_TARGET: ${{ inputs.k8s-target }}
|
K8S_TARGET: ${{ inputs.k8s-target }}
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.kube
|
mkdir -p ~/.kube
|
||||||
@@ -30,7 +33,7 @@ runs:
|
|||||||
env:
|
env:
|
||||||
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
|
VAULT_MASTER_PASSWORD: ${{ inputs.vault-master-password }}
|
||||||
ANSIBLE_USER: ${{ inputs.ansible-user }}
|
ANSIBLE_USER: ${{ inputs.ansible-user }}
|
||||||
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
|
SSH_AUTH_SOCK: ${{ inputs.ssh-auth-sock }}
|
||||||
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
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -26,20 +26,17 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
vault-master-password: ${{ secrets.VAULT_MASTER_PASSWORD }}
|
vault-master-password: ${{ secrets.VAULT_MASTER_PASSWORD }}
|
||||||
ansible-user: ${{ secrets.ANSIBLE_USER }}
|
ansible-user: ${{ secrets.ANSIBLE_USER }}
|
||||||
trusted-hosts: ${{ secrets.TRUSTED_HOSTS }}
|
|
||||||
|
|
||||||
- name: Setup Terraform
|
|
||||||
uses: hashicorp/setup-terraform@v1
|
|
||||||
with:
|
|
||||||
terraform_version: 1.9.6
|
|
||||||
|
|
||||||
|
- name: Setup Terraform environment
|
||||||
|
uses: ./.github/actions/setup-terraform-env
|
||||||
|
|
||||||
- name: Setup Kubernetes Environment
|
- name: Setup Kubernetes Environment
|
||||||
uses: ./.github/actions/setup-k8s-env
|
uses: ./.github/actions/setup-k8s-env
|
||||||
with:
|
with:
|
||||||
vault-master-password: ${{ secrets.VAULT_MASTER_PASSWORD }}
|
vault-master-password: ${{ secrets.VAULT_MASTER_PASSWORD }}
|
||||||
ansible-user: ${{ secrets.ANSIBLE_USER }}
|
ansible-user: ${{ secrets.ANSIBLE_USER }}
|
||||||
|
|
||||||
- name: Get Host Info
|
- name: Get remote host info
|
||||||
uses: ./.github/actions/get-host-info
|
uses: ./.github/actions/get-host-info
|
||||||
id: get-host-info
|
id: get-host-info
|
||||||
with:
|
with:
|
||||||
@@ -57,3 +54,7 @@ jobs:
|
|||||||
- name: Test terraform
|
- name: Test terraform
|
||||||
run: |
|
run: |
|
||||||
terraform --version
|
terraform --version
|
||||||
|
|
||||||
|
- name: Show remote host info
|
||||||
|
run: |
|
||||||
|
echo "System ID: ${{ steps.get-host-info.outputs.system_id }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user