This commit is contained in:
Dawid Dziurla 2020-03-21 17:06:40 +01:00
parent afff5c9738
commit 71c08da46c
No known key found for this signature in database
GPG Key ID: 7B6D8368172E9B0B
8 changed files with 71 additions and 23 deletions

18
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,18 @@
name: Test Action
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run
uses: ./
with:
playbook: playbook.yml
options: |
--inventory=localhost,
--connection=local
--verbose

View File

@ -1,7 +1,7 @@
FROM alpine:3.10
FROM alpine
COPY LICENSE README.md /
RUN apk -U add ansible bash
COPY entrypoint.sh /entrypoint.sh
COPY main.sh /
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/main.sh"]

View File

@ -1,7 +1,7 @@
The MIT License (MIT)
Copyright (c) 2018 GitHub, Inc. and contributors
Copyright (c) 2020 Dawid Dziurla
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,5 +1,2 @@
# Container Action Template
# Run Ansible playbook Github Action
To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/).
For info on how to build your first Container action, see the [toolkit docs folder](https://github.com/actions/toolkit/blob/master/docs/container-action.md).

View File

@ -1,12 +1,18 @@
name: 'Container Action Template'
description: 'Get started with Container actions'
author: 'GitHub'
name: Run Ansible playbook
description: Execute Ansible playbook on selected hosts
branding:
color: red
icon: play
inputs:
myInput:
description: 'Input to use'
default: 'world'
playbook:
description: Ansible playbook filepath
required: true
key:
description: SSH private key used to connect to the host
required: false
options:
description: Extra options that should be passed to ansible-playbook command
required: false
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.myInput }}
using: docker
image: Dockerfile

View File

@ -1,3 +0,0 @@
#!/bin/sh -l
echo "hello $1"

23
main.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
set -e
playbook="$INPUT_PLAYBOOK"
key="$INPUT_KEY"
options="$INPUT_OPTIONS"
if test -z "$playbook"; then
echo "You need to specify 'playbook' input (Ansible playbook filepath)"
exit 1
fi
if test -n "$key"; then
mkdir -p ~/.ssh
echo "$key" > ~/.ssh/id_rsa
chmod 400 ~/.ssh/id_rsa
fi
export ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_FORCE_COLOR=True
ansible-playbook "$options" "$playbook"

7
playbook.yml Normal file
View File

@ -0,0 +1,7 @@
- name: Test Action
hosts: all
tasks:
- name: Copy action.yml
copy:
src: action.yml
dest: /tmp/action.yml