main: update

- print colored command
- print colored errors
- info messages prefixed with '==>'
- consistency
This commit is contained in:
Dawid Dziurla 2020-04-06 23:35:18 +02:00 committed by GitHub
parent 8cd63cd522
commit 8973eff607
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

36
main.sh
View File

@ -2,8 +2,8 @@
set -e set -e
default_inventory="hosts" inventory_file="hosts"
default_vault_file=".vault_password" vault_password_file=".vault_password"
playbook="$INPUT_PLAYBOOK" playbook="$INPUT_PLAYBOOK"
directory="$INPUT_DIRECTORY" directory="$INPUT_DIRECTORY"
@ -13,39 +13,39 @@ vault_password="$INPUT_VAULT_PASSWORD"
options="$INPUT_OPTIONS" options="$INPUT_OPTIONS"
if test -z "$playbook"; then if test -z "$playbook"; then
echo "You need to specify 'playbook' input (Ansible playbook filepath)" echo "::error::You need to specify 'playbook' input (Ansible playbook filepath)"
exit 1 exit 1
fi fi
if test -z "$key"; then if test -z "$key"; then
echo "You need to specify 'key' input (SSH private key)" echo "::error::You need to specify 'key' input (SSH private key)"
exit 1 exit 1
fi fi
if test -n "$directory"; then
cd "$directory"
fi
mkdir -p "$HOME/.ssh" mkdir -p "$HOME/.ssh"
echo "$key" > "$HOME/.ssh/id_rsa" echo "$key" > "$HOME/.ssh/id_rsa"
chmod 600 "$HOME/.ssh/id_rsa" chmod 600 "$HOME/.ssh/id_rsa"
if [ "$inventory" ]; then if test -n "$directory"; then
echo "Writing inventory with custom content:" echo "==> Changing directory to: $directory"
echo -e "$inventory" | tee "$default_inventory" cd "$directory"
options="${options} --inventory ${default_inventory}"
fi fi
if [ "$vault_password" ]; then if test -n "$inventory"; then
echo "Setting vault password" echo "==> Writing inventory with custom content:"
echo "$vault_password" > "$default_vault_file" echo -e "$inventory" | tee "$inventory_file"
options="${options} --vault-password-file ${default_vault_file}" options="$options --inventory $inventory_file"
fi fi
echo "$options" if test -n "$vault_password"; then
echo "$playbook" echo "==> Setting vault password"
echo "$vault_password" > "$vault_password_file"
options="$options --vault-password-file $vault_password_file"
fi
export ANSIBLE_HOST_KEY_CHECKING=False export ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_FORCE_COLOR=True export ANSIBLE_FORCE_COLOR=True
echo "[command]ansible-playbook $options $playbook"
ansible-playbook $options $playbook ansible-playbook $options $playbook