mirror of
https://github.com/dawidd6/action-ansible-playbook.git
synced 2024-12-23 04:37:29 +00:00
main: update
- print colored command - print colored errors - info messages prefixed with '==>' - consistency
This commit is contained in:
parent
8cd63cd522
commit
8973eff607
1 changed files with 18 additions and 18 deletions
36
main.sh
36
main.sh
|
@ -2,8 +2,8 @@
|
|||
|
||||
set -e
|
||||
|
||||
default_inventory="hosts"
|
||||
default_vault_file=".vault_password"
|
||||
inventory_file="hosts"
|
||||
vault_password_file=".vault_password"
|
||||
|
||||
playbook="$INPUT_PLAYBOOK"
|
||||
directory="$INPUT_DIRECTORY"
|
||||
|
@ -13,39 +13,39 @@ vault_password="$INPUT_VAULT_PASSWORD"
|
|||
options="$INPUT_OPTIONS"
|
||||
|
||||
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
|
||||
fi
|
||||
|
||||
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
|
||||
fi
|
||||
|
||||
if test -n "$directory"; then
|
||||
cd "$directory"
|
||||
fi
|
||||
|
||||
mkdir -p "$HOME/.ssh"
|
||||
echo "$key" > "$HOME/.ssh/id_rsa"
|
||||
chmod 600 "$HOME/.ssh/id_rsa"
|
||||
|
||||
if [ "$inventory" ]; then
|
||||
echo "Writing inventory with custom content:"
|
||||
echo -e "$inventory" | tee "$default_inventory"
|
||||
options="${options} --inventory ${default_inventory}"
|
||||
if test -n "$directory"; then
|
||||
echo "==> Changing directory to: $directory"
|
||||
cd "$directory"
|
||||
fi
|
||||
|
||||
if [ "$vault_password" ]; then
|
||||
echo "Setting vault password"
|
||||
echo "$vault_password" > "$default_vault_file"
|
||||
options="${options} --vault-password-file ${default_vault_file}"
|
||||
if test -n "$inventory"; then
|
||||
echo "==> Writing inventory with custom content:"
|
||||
echo -e "$inventory" | tee "$inventory_file"
|
||||
options="$options --inventory $inventory_file"
|
||||
fi
|
||||
|
||||
echo "$options"
|
||||
echo "$playbook"
|
||||
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
|
||||
|
||||
export ANSIBLE_HOST_KEY_CHECKING=False
|
||||
export ANSIBLE_FORCE_COLOR=True
|
||||
|
||||
echo "[command]ansible-playbook $options $playbook"
|
||||
|
||||
ansible-playbook $options $playbook
|
||||
|
|
Loading…
Reference in a new issue