28 Commits
v1.0.0 ... v1

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
Dawid Dziurla
f13d1bd963 Merge pull request #3 from dawidd6/directory
Directory
2020-03-24 23:40:03 +01:00
Dawid Dziurla
c94ab57c30 main: don't require directory input to be set 2020-03-24 22:44:07 +01:00
Dawid Dziurla
7294666400 action: remove default value for directory input 2020-03-24 22:43:22 +01:00
Dawid Dziurla
6bf8287520 workflows: change default directory to ./ 2020-03-24 22:32:24 +01:00
Dawid Dziurla
bf72c8dfa3 README: change default directory to ./ 2020-03-24 22:30:07 +01:00
Dawid Dziurla
5f9b0124a8 action: change default directory to ./
github.workspace directory is not available in container
2020-03-24 22:29:40 +01:00
Dawid Dziurla
05885e8435 workflows: add directory input 2020-03-24 22:26:46 +01:00
Dawid Dziurla
6125b23431 main: add directory input 2020-03-24 22:23:41 +01:00
Dawid Dziurla
106317ddaa README: add directory input 2020-03-24 22:23:30 +01:00
Dawid Dziurla
13970a992f action: add directory input 2020-03-24 22:23:19 +01:00
Dawid Dziurla
ca781d9ed5 Dockerfile.test: don't unlock root account 2020-03-23 23:15:41 +01:00
Dawid Dziurla
2f1261582a README: fix usage 2020-03-23 23:12:27 +01:00
Julian Pelizäus
6d1f107198 Add capabilities for custom inventory and vault password 2020-03-22 20:30:44 +01:00
5 changed files with 77 additions and 13 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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
```

View File

@@ -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
View File

@@ -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