feat: add ansible-playbook command

This commit is contained in:
2025-08-14 07:27:55 -07:00
parent e32d38ea2f
commit 6131f838c2
2 changed files with 61 additions and 14 deletions

View File

@@ -20,8 +20,8 @@ inputs:
description: Ansible playbook filepath description: Ansible playbook filepath
required: true required: true
inventory: inventory:
description: Ansible inventory filepath description: Ansible inventory expression or filepath (multiple lines will be converted to a file)
required: true required: false
requirements: requirements:
description: Ansible Galaxy requirements filepath description: Ansible Galaxy requirements filepath
required: false required: false
@@ -34,15 +34,6 @@ inputs:
vault_password: vault_password:
description: The password used for decrypting vaulted files description: The password used for decrypting vaulted files
required: false required: false
private_key:
description: SSH private key used to connect to the host
required: false
known_hosts:
description: Contents of SSH known_hosts file
required: false
options:
description: Extra options that should be passed to ansible-playbook command
required: false
become: become:
description: Set to "true" if root is required for running your playbook description: Set to "true" if root is required for running your playbook
required: false required: false
@@ -51,6 +42,9 @@ inputs:
description: Set to "true" to enable check (dry-run) mode description: Set to "true" to enable check (dry-run) mode
required: false required: false
default: false default: false
options:
description: Extra options that should be passed to ansible-playbook command
required: false
runs: runs:
using: docker using: docker
image: Dockerfile image: Dockerfile

View File

@@ -25,7 +25,7 @@ if [ -z "${INPUT_INVENTORY:-}" ] ; then
exit 1 exit 1
fi fi
# Setup Variables # Setup Provisioner Variables
provisioner_name=${INPUT_PKI_PROVISIONER_NAME:-"ansible"} provisioner_name=${INPUT_PKI_PROVISIONER_NAME:-"ansible"}
provisioner_password=${INPUT_PKI_PROVISIONER_PASSWORD} provisioner_password=${INPUT_PKI_PROVISIONER_PASSWORD}
default_cert_subject="ansible-kraussnet-action-runner@$(hostname -f)" default_cert_subject="ansible-kraussnet-action-runner@$(hostname -f)"
@@ -53,5 +53,58 @@ step ssh certificate "${user_cert_subject}" ~/.ssh/id_ecdsa.pub --sign --provisi
echo "Obtained User Certificate from CA" echo "Obtained User Certificate from CA"
ssh-keygen -L -f ~/.ssh/id_ecdsa-cert.pub ssh-keygen -L -f ~/.ssh/id_ecdsa-cert.pub
# Run a test command (will be replaced with the Ansible command) # Process the inventory parameter
ssh ansible@rpi-ns1.lan.kraussnet.com 'echo "Hello from $(hostname -f)"' inventory=""
if [ "${INPUT_INVENTORY}" =~ $'\n' ] ; then
echo "${INPUT_INVENTORY}" > /tmp/inventory
inventory="/tmp/inventory"
else
inventory="${INPUT_INVENTORY}"
fi
echo "Using inventory ${inventory}"
# Process Ansible Galaxy requirements
if [ ! -z "${INPUT_REQUIREMENTS:-}" ] ; then
ansible-galaxy install -r "${INPUT_REQUIREMENTS}"
echo "Installed Galaxy Dependencies"
fi
# Change the working directory
if [ ! - z "${INPUT_DIRECTORY:-}" ] ; then
cd "${INPUT_DIRECTORY}"
echo "Changed working directory to $(pwd)"
fi
# Process Ansible Configuration
if [ ! -z "${INPUT_CONFIGURATION:-}" ] ; then
if [ -f ./ansible.cfg ] ; then
echo "An existing ansible.cfg file is in the current working directory"
exit 1
fi
echo "${INPUT_CONFIGURATION}" > ./ansible.cfg
echo "Created $(pwd)/ansible.cfg"
fi
# Setup and Run Ansible Playbook
cmd=""
become="${INPUT_BECOME:-false}"
check_mode="${INPUT_CHECK_MODE:-false}"
if [ "${become,,}" == "true" ] ; then
cmd="${cmd} -b"
fi
if [ "${check_mode,,}" == "true" ] ; then
cmd="${cmd} --check"
fi
if [ ! -z "${INPUT_VAULT_PASSWORD:-}" ] ; then
echo "${INPUT_VAULT_PASSWORD}" > /tmp/vault_password
cmd="${cmd} --vault-password-file /tmp/vault_password"
fi
cmd="${cmd} --inventory ${inventory} ${INPUT_PLAYBOOK}"
print "Ansible Command: ansible-playbook ${cmd}"
ansible-playbook $cmd