diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b5bbf1..7bf949e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,8 @@ 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 diff --git a/README.md b/README.md index 0433c86..44b6202 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ An action that executes given Ansible playbook on selected hosts. uses: dawidd6/action-ansible-playbook@master with: playbook: deploy.yml + directory: ./ key: ${{secrets.SSH_PRIVATE_KEY}} options: | --inventory hosts diff --git a/action.yml b/action.yml index 0d1626e..bd5889b 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,9 @@ 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 diff --git a/main.sh b/main.sh index c16dbc5..17a5d37 100755 --- a/main.sh +++ b/main.sh @@ -3,6 +3,7 @@ set -e playbook="$INPUT_PLAYBOOK" +directory="$INPUT_DIRECTORY" key="$INPUT_KEY" options="$INPUT_OPTIONS" @@ -16,6 +17,10 @@ if test -z "$key"; then exit 1 fi +if test -n "$directory"; then + cd "$directory" +fi + mkdir -p "$HOME/.ssh" echo "$key" > "$HOME/.ssh/id_rsa" chmod 600 "$HOME/.ssh/id_rsa"