mirror of
https://github.com/dawidd6/action-ansible-playbook.git
synced 2026-01-11 14:01:41 -07:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47f48fd0e8 | ||
|
|
55d6336eea | ||
|
|
2be8c5b7f9 | ||
|
|
5240df9b51 | ||
|
|
bfdba4708c | ||
|
|
3f717ecb7e | ||
|
|
6befc53422 | ||
|
|
b898645779 | ||
|
|
594eddd07c | ||
|
|
9f87a197cc | ||
|
|
b870361b37 | ||
|
|
32a48fb292 | ||
|
|
8973eff607 | ||
|
|
8cd63cd522 | ||
|
|
d300a38a99 | ||
|
|
6d1f107198 |
26
.github/workflows/test.yml
vendored
26
.github/workflows/test.yml
vendored
@@ -3,7 +3,7 @@ name: Test Action
|
|||||||
on: push
|
on: push
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test-remote:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
@@ -26,6 +26,11 @@ jobs:
|
|||||||
-e INPUT_KEY="${{secrets.SSH_PRIVATE_KEY}}" \
|
-e INPUT_KEY="${{secrets.SSH_PRIVATE_KEY}}" \
|
||||||
-e INPUT_OPTIONS="--inventory hosts --limit remote" \
|
-e INPUT_OPTIONS="--inventory hosts --limit remote" \
|
||||||
action
|
action
|
||||||
|
test-local:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
- name: Test local
|
- name: Test local
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -33,4 +38,21 @@ jobs:
|
|||||||
key: ${{secrets.SSH_PRIVATE_KEY}}
|
key: ${{secrets.SSH_PRIVATE_KEY}}
|
||||||
options: |
|
options: |
|
||||||
--inventory hosts
|
--inventory hosts
|
||||||
--limit local
|
--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
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -6,14 +6,20 @@ An action that executes given Ansible playbook on selected hosts.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Run playbook
|
- name: Run playbook
|
||||||
uses: dawidd6/action-ansible-playbook@master
|
uses: dawidd6/action-ansible-playbook@v1
|
||||||
with:
|
with:
|
||||||
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 group1
|
||||||
--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
|
||||||
|
|||||||
39
main.sh
39
main.sh
@@ -2,33 +2,54 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
inventory_file="hosts"
|
||||||
|
vault_password_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
|
||||||
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"
|
||||||
|
|
||||||
echo "$options"
|
if test -n "$directory"; then
|
||||||
echo "$playbook"
|
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_HOST_KEY_CHECKING=False
|
||||||
export ANSIBLE_FORCE_COLOR=True
|
export ANSIBLE_FORCE_COLOR=True
|
||||||
|
|
||||||
ansible-playbook $options $playbook
|
echo "[command]ansible-playbook $options $playbook"
|
||||||
|
|
||||||
|
ansible-playbook $options $playbook
|
||||||
|
|||||||
Reference in New Issue
Block a user