mirror of
https://github.com/dawidd6/action-ansible-playbook.git
synced 2026-01-11 05:51:42 -07:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47f48fd0e8 | ||
|
|
55d6336eea | ||
|
|
2be8c5b7f9 | ||
|
|
5240df9b51 | ||
|
|
bfdba4708c | ||
|
|
3f717ecb7e | ||
|
|
6befc53422 | ||
|
|
b898645779 | ||
|
|
594eddd07c | ||
|
|
9f87a197cc | ||
|
|
b870361b37 | ||
|
|
32a48fb292 | ||
|
|
8973eff607 | ||
|
|
8cd63cd522 | ||
|
|
d300a38a99 | ||
|
|
f13d1bd963 | ||
|
|
c94ab57c30 | ||
|
|
7294666400 | ||
|
|
6bf8287520 | ||
|
|
bf72c8dfa3 | ||
|
|
5f9b0124a8 | ||
|
|
05885e8435 | ||
|
|
6125b23431 | ||
|
|
106317ddaa | ||
|
|
13970a992f | ||
|
|
ca781d9ed5 | ||
|
|
2f1261582a | ||
|
|
6d1f107198 |
29
.github/workflows/test.yml
vendored
29
.github/workflows/test.yml
vendored
@@ -3,7 +3,7 @@ name: Test Action
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
test:
|
||||
test-remote:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
@@ -21,10 +21,16 @@ jobs:
|
||||
--link host \
|
||||
-v $PWD:/wd \
|
||||
-w /wd \
|
||||
-e INPUT_PLAYBOOK=playbook.yml \
|
||||
-e INPUT_PLAYBOOK="playbook.yml" \
|
||||
-e INPUT_DIRECTORY="./" \
|
||||
-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:
|
||||
@@ -32,4 +38,21 @@ jobs:
|
||||
key: ${{secrets.SSH_PRIVATE_KEY}}
|
||||
options: |
|
||||
--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
|
||||
|
||||
@@ -3,13 +3,12 @@ FROM alpine
|
||||
RUN apk -U add openssh-server openssh-sftp-server sudo python3
|
||||
RUN adduser -D user
|
||||
RUN passwd -u user
|
||||
RUN passwd -u root
|
||||
RUN echo "user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers
|
||||
RUN echo "PasswordAuthentication no" > /etc/ssh/sshd_config
|
||||
RUN echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config
|
||||
RUN echo "AuthorizedKeysFile /etc/ssh/authorized_keys" >> /etc/ssh/sshd_config
|
||||
RUN echo "PermitRootLogin no" >> /etc/ssh/sshd_config
|
||||
RUN echo "Subsystem sftp /usr/lib/ssh/sftp-server" >> /etc/ssh/sshd_config
|
||||
RUN echo "Subsystem sftp /usr/lib/ssh/sftp-server" >> /etc/ssh/sshd_config
|
||||
|
||||
RUN ssh-keygen -A
|
||||
|
||||
|
||||
13
README.md
13
README.md
@@ -6,13 +6,20 @@ An action that executes given Ansible playbook on selected hosts.
|
||||
|
||||
```yaml
|
||||
- name: Run playbook
|
||||
uses: dawidd6/action-ansible-playbook
|
||||
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
|
||||
```
|
||||
|
||||
@@ -7,9 +7,18 @@ inputs:
|
||||
playbook:
|
||||
description: Ansible playbook filepath
|
||||
required: true
|
||||
directory:
|
||||
description: Root directory of Ansible project (defaults to current)
|
||||
required: false
|
||||
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
|
||||
|
||||
36
main.sh
36
main.sh
@@ -2,17 +2,23 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -20,10 +26,30 @@ 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
|
||||
|
||||
ansible-playbook $options $playbook
|
||||
echo "[command]ansible-playbook $options $playbook"
|
||||
|
||||
ansible-playbook $options $playbook
|
||||
|
||||
Reference in New Issue
Block a user