mirror of
https://github.com/dawidd6/action-ansible-playbook.git
synced 2024-11-22 15:32:18 +00:00
Merge pull request #1 from Roosterfish/feature/custom-inventory
Add capabilities for custom inventory and vault password
This commit is contained in:
commit
8cd63cd522
3 changed files with 31 additions and 2 deletions
|
@ -11,8 +11,14 @@ An action that executes given Ansible playbook on selected hosts.
|
||||||
playbook: deploy.yml
|
playbook: deploy.yml
|
||||||
directory: ./
|
directory: ./
|
||||||
key: ${{secrets.SSH_PRIVATE_KEY}}
|
key: ${{secrets.SSH_PRIVATE_KEY}}
|
||||||
|
inventory: |
|
||||||
|
[all]
|
||||||
|
example.com
|
||||||
|
|
||||||
|
[group1]
|
||||||
|
example.com
|
||||||
|
vault_password: ${{secrets.VAULT_PASSWORD}}
|
||||||
options: |
|
options: |
|
||||||
--inventory hosts
|
|
||||||
--limit dev
|
--limit dev
|
||||||
--extra-vars hello=there
|
--extra-vars hello=there
|
||||||
--verbose
|
--verbose
|
||||||
|
|
|
@ -13,6 +13,12 @@ inputs:
|
||||||
key:
|
key:
|
||||||
description: SSH private key used to connect to the host
|
description: SSH private key used to connect to the host
|
||||||
required: true
|
required: true
|
||||||
|
inventory:
|
||||||
|
description: Custom content to write into hosts
|
||||||
|
required: false
|
||||||
|
vault_password:
|
||||||
|
description: The password used for decrypting vaulted files
|
||||||
|
required: false
|
||||||
options:
|
options:
|
||||||
description: Extra options that should be passed to ansible-playbook command
|
description: Extra options that should be passed to ansible-playbook command
|
||||||
required: false
|
required: false
|
||||||
|
|
19
main.sh
19
main.sh
|
@ -2,9 +2,14 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
default_inventory="hosts"
|
||||||
|
default_vault_file=".vault_password"
|
||||||
|
|
||||||
playbook="$INPUT_PLAYBOOK"
|
playbook="$INPUT_PLAYBOOK"
|
||||||
directory="$INPUT_DIRECTORY"
|
directory="$INPUT_DIRECTORY"
|
||||||
key="$INPUT_KEY"
|
key="$INPUT_KEY"
|
||||||
|
inventory="$INPUT_INVENTORY"
|
||||||
|
vault_password="$INPUT_VAULT_PASSWORD"
|
||||||
options="$INPUT_OPTIONS"
|
options="$INPUT_OPTIONS"
|
||||||
|
|
||||||
if test -z "$playbook"; then
|
if test -z "$playbook"; then
|
||||||
|
@ -25,10 +30,22 @@ 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
|
||||||
|
echo "Writing inventory with custom content:"
|
||||||
|
echo -e "$inventory" | tee "$default_inventory"
|
||||||
|
options="${options} --inventory ${default_inventory}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$vault_password" ]; then
|
||||||
|
echo "Setting vault password"
|
||||||
|
echo "$vault_password" > "$default_vault_file"
|
||||||
|
options="${options} --vault-password-file ${default_vault_file}"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "$options"
|
echo "$options"
|
||||||
echo "$playbook"
|
echo "$playbook"
|
||||||
|
|
||||||
export ANSIBLE_HOST_KEY_CHECKING=False
|
export ANSIBLE_HOST_KEY_CHECKING=False
|
||||||
export ANSIBLE_FORCE_COLOR=True
|
export ANSIBLE_FORCE_COLOR=True
|
||||||
|
|
||||||
ansible-playbook $options $playbook
|
ansible-playbook $options $playbook
|
||||||
|
|
Loading…
Reference in a new issue