16 Commits

Author SHA1 Message Date
Dawid Dziurla
47f48fd0e8 workflows: pass -e options 2020-04-07 00:58:47 +02:00
Dawid Dziurla
55d6336eea main: use awk to trim whitespace 2020-04-07 00:57:21 +02:00
Dawid Dziurla
2be8c5b7f9 main: don't print inventory 2020-04-07 00:14:34 +02:00
Dawid Dziurla
5240df9b51 main: just write inventory 2020-04-07 00:12:40 +02:00
Dawid Dziurla
bfdba4708c README: update 2020-04-07 00:07:48 +02:00
Dawid Dziurla
3f717ecb7e main: trim whitespace in options 2020-04-07 00:06:51 +02:00
Dawid Dziurla
6befc53422 workflows: another test job 2020-04-07 00:03:41 +02:00
Dawid Dziurla
b898645779 main: flatten options 2020-04-07 00:01:30 +02:00
Dawid Dziurla
594eddd07c workflows: no fold 2020-04-06 23:53:57 +02:00
Dawid Dziurla
9f87a197cc main: trim newlines from command 2020-04-06 23:51:22 +02:00
Dawid Dziurla
b870361b37 workflows: run separate jobs 2020-04-06 23:45:33 +02:00
Dawid Dziurla
32a48fb292 workflows: fold options 2020-04-06 23:39:47 +02:00
Dawid Dziurla
8973eff607 main: update
- print colored command
- print colored errors
- info messages prefixed with '==>'
- consistency
2020-04-06 23:35:18 +02:00
Dawid Dziurla
8cd63cd522 Merge pull request #1 from Roosterfish/feature/custom-inventory
Add capabilities for custom inventory and vault password
2020-04-06 23:15:07 +02:00
Dawid Dziurla
d300a38a99 README: point to a tag instead of master branch 2020-03-29 23:18:04 +02:00
Julian Pelizäus
6d1f107198 Add capabilities for custom inventory and vault password 2020-03-22 20:30:44 +01:00
4 changed files with 69 additions and 14 deletions

View File

@@ -3,7 +3,7 @@ name: Test Action
on: push
jobs:
test:
test-remote:
runs-on: ubuntu-latest
steps:
- name: Checkout code
@@ -26,6 +26,11 @@ jobs:
-e INPUT_KEY="${{secrets.SSH_PRIVATE_KEY}}" \
-e INPUT_OPTIONS="--inventory hosts --limit remote" \
action
test-local:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Test local
uses: ./
with:
@@ -34,3 +39,20 @@ jobs:
options: |
--inventory hosts
--limit local
test-local-more:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Test local
uses: ./
with:
playbook: playbook.yml
key: ${{secrets.SSH_PRIVATE_KEY}}
vault_password: test
inventory: |
[all]
localhost ansible_user=root ansible_connection=local
options: |
-e key1=val1
-e key2=val2

View File

@@ -6,14 +6,20 @@ An action that executes given Ansible playbook on selected hosts.
```yaml
- name: Run playbook
uses: dawidd6/action-ansible-playbook@master
uses: dawidd6/action-ansible-playbook@v1
with:
playbook: deploy.yml
directory: ./
key: ${{secrets.SSH_PRIVATE_KEY}}
inventory: |
[all]
example.com
[group1]
example.com
vault_password: ${{secrets.VAULT_PASSWORD}}
options: |
--inventory hosts
--limit dev
--limit group1
--extra-vars hello=there
--verbose
```

View File

@@ -13,6 +13,12 @@ inputs:
key:
description: SSH private key used to connect to the host
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:
description: Extra options that should be passed to ansible-playbook command
required: false

37
main.sh
View File

@@ -2,33 +2,54 @@
set -e
inventory_file="hosts"
vault_password_file=".vault_password"
playbook="$INPUT_PLAYBOOK"
directory="$INPUT_DIRECTORY"
key="$INPUT_KEY"
inventory="$INPUT_INVENTORY"
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"
echo "$options"
echo "$playbook"
if test -n "$directory"; then
echo "==> Changing directory to: $directory"
cd "$directory"
fi
if test -n "$options"; then
options="$(echo "$options" | tr '\n' ' ' | awk '{$1=$1};1')"
fi
if test -n "$inventory"; then
echo "==> Setting inventory"
echo "$inventory" > "$inventory_file"
options="$options --inventory $inventory_file"
fi
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