From 71c08da46c25f048b4ddc20c1f6798c81ba7c209 Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Sat, 21 Mar 2020 17:06:40 +0100 Subject: [PATCH] init --- .github/workflows/test.yml | 18 ++++++++++++++++++ Dockerfile | 8 ++++---- LICENSE | 2 +- README.md | 5 +---- action.yml | 28 +++++++++++++++++----------- entrypoint.sh | 3 --- main.sh | 23 +++++++++++++++++++++++ playbook.yml | 7 +++++++ 8 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100755 entrypoint.sh create mode 100755 main.sh create mode 100644 playbook.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..235def2 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index af66730..f4346cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/LICENSE b/LICENSE index a67dca8..38195be 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 25842b5..ebb1b9d 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/action.yml b/action.yml index 4353abb..311659a 100644 --- a/action.yml +++ b/action.yml @@ -1,12 +1,18 @@ -name: 'Container Action Template' -description: 'Get started with Container actions' -author: 'GitHub' -inputs: - myInput: - description: 'Input to use' - default: 'world' +name: Run Ansible playbook +description: Execute Ansible playbook on selected hosts +branding: + color: red + icon: play +inputs: + 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 diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 3b8cd2d..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -l - -echo "hello $1" diff --git a/main.sh b/main.sh new file mode 100755 index 0000000..ec7ce01 --- /dev/null +++ b/main.sh @@ -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" \ No newline at end of file diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..fa20c3e --- /dev/null +++ b/playbook.yml @@ -0,0 +1,7 @@ +- name: Test Action + hosts: all + tasks: + - name: Copy action.yml + copy: + src: action.yml + dest: /tmp/action.yml \ No newline at end of file