2020-03-21 19:01:42 +00:00
|
|
|
#!/bin/sh
|
2020-03-21 16:06:40 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2020-04-06 21:35:18 +00:00
|
|
|
inventory_file="hosts"
|
|
|
|
vault_password_file=".vault_password"
|
2020-03-22 19:30:44 +00:00
|
|
|
|
2020-03-21 16:06:40 +00:00
|
|
|
playbook="$INPUT_PLAYBOOK"
|
2020-03-24 21:23:41 +00:00
|
|
|
directory="$INPUT_DIRECTORY"
|
2020-03-21 16:06:40 +00:00
|
|
|
key="$INPUT_KEY"
|
2020-03-22 19:30:44 +00:00
|
|
|
inventory="$INPUT_INVENTORY"
|
|
|
|
vault_password="$INPUT_VAULT_PASSWORD"
|
2020-03-21 16:06:40 +00:00
|
|
|
options="$INPUT_OPTIONS"
|
|
|
|
|
|
|
|
if test -z "$playbook"; then
|
2020-04-06 21:35:18 +00:00
|
|
|
echo "::error::You need to specify 'playbook' input (Ansible playbook filepath)"
|
2020-03-21 16:06:40 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-03-21 19:54:44 +00:00
|
|
|
if test -z "$key"; then
|
2020-04-06 21:35:18 +00:00
|
|
|
echo "::error::You need to specify 'key' input (SSH private key)"
|
2020-03-21 19:54:44 +00:00
|
|
|
exit 1
|
2020-03-21 16:06:40 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-21 19:54:44 +00:00
|
|
|
mkdir -p "$HOME/.ssh"
|
|
|
|
echo "$key" > "$HOME/.ssh/id_rsa"
|
|
|
|
chmod 600 "$HOME/.ssh/id_rsa"
|
|
|
|
|
2020-04-06 21:35:18 +00:00
|
|
|
if test -n "$directory"; then
|
|
|
|
echo "==> Changing directory to: $directory"
|
|
|
|
cd "$directory"
|
2020-03-22 19:30:44 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-06 22:01:30 +00:00
|
|
|
if test -n "$options"; then
|
2020-04-06 22:57:21 +00:00
|
|
|
options="$(echo "$options" | tr '\n' ' ' | awk '{$1=$1};1')"
|
2020-04-06 22:01:30 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-06 21:35:18 +00:00
|
|
|
if test -n "$inventory"; then
|
2020-04-06 22:12:40 +00:00
|
|
|
echo "==> Setting inventory"
|
|
|
|
echo "$inventory" > "$inventory_file"
|
2020-04-06 21:35:18 +00:00
|
|
|
options="$options --inventory $inventory_file"
|
2020-03-22 19:30:44 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-06 21:35:18 +00:00
|
|
|
if test -n "$vault_password"; then
|
|
|
|
echo "==> Setting vault password"
|
|
|
|
echo "$vault_password" > "$vault_password_file"
|
|
|
|
options="$options --vault-password-file $vault_password_file"
|
|
|
|
fi
|
2020-03-21 16:10:07 +00:00
|
|
|
|
2020-03-21 16:06:40 +00:00
|
|
|
export ANSIBLE_HOST_KEY_CHECKING=False
|
|
|
|
export ANSIBLE_FORCE_COLOR=True
|
|
|
|
|
2020-04-06 22:01:30 +00:00
|
|
|
echo "[command]ansible-playbook $options $playbook"
|
2020-04-06 21:35:18 +00:00
|
|
|
|
2020-03-22 19:30:44 +00:00
|
|
|
ansible-playbook $options $playbook
|