From 13970a992f712d049c97124026983160b226c39f Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Mar 2020 22:23:19 +0100 Subject: [PATCH 1/9] action: add directory input --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index 0d1626e..da51313 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,10 @@ inputs: playbook: description: Ansible playbook filepath required: true + directory: + description: Root directory of Ansible project + required: false + default: ${{github.workspace}} key: description: SSH private key used to connect to the host required: true From 106317ddaa70e333edc8652b99c64f6dae35896b Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Mar 2020 22:23:30 +0100 Subject: [PATCH 2/9] README: add directory input --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5ea5866..1d40ce8 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 with: playbook: deploy.yml + directory: ${{github.workspace}} key: ${{secrets.SSH_PRIVATE_KEY}} options: | --inventory hosts From 6125b234312cf8108f240d9e053567297cfeb9ed Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Mar 2020 22:23:41 +0100 Subject: [PATCH 3/9] main: add directory input --- main.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.sh b/main.sh index c16dbc5..6e15928 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" @@ -11,11 +12,18 @@ if test -z "$playbook"; then exit 1 fi +if test -z "$directory"; then + echo "You need to specify 'directory' input (root Ansible project directory)" + exit 1 +fi + if test -z "$key"; then echo "You need to specify 'key' input (SSH private key)" exit 1 fi +cd "$directory" + mkdir -p "$HOME/.ssh" echo "$key" > "$HOME/.ssh/id_rsa" chmod 600 "$HOME/.ssh/id_rsa" From 05885e84352819df8f932b0fa44fc1bd88733c6c Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Mar 2020 22:26:46 +0100 Subject: [PATCH 4/9] workflows: add directory input --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b5bbf1..4bbe18a 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="${{github.workspace}}" \ -e INPUT_KEY="${{secrets.SSH_PRIVATE_KEY}}" \ -e INPUT_OPTIONS="--inventory hosts --limit remote" \ action From 5f9b0124a8d5b02684ebf221aca8356ff494113f Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Mar 2020 22:29:40 +0100 Subject: [PATCH 5/9] action: change default directory to ./ github.workspace directory is not available in container --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index da51313..31a55ba 100644 --- a/action.yml +++ b/action.yml @@ -10,7 +10,7 @@ inputs: directory: description: Root directory of Ansible project required: false - default: ${{github.workspace}} + default: ./ key: description: SSH private key used to connect to the host required: true From bf72c8dfa3cf8de498a8622b5e064cdd79acbe9b Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Mar 2020 22:30:07 +0100 Subject: [PATCH 6/9] README: change default directory to ./ --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d40ce8..8b9b4b3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ An action that executes given Ansible playbook on selected hosts. uses: dawidd6/action-ansible-playbook with: playbook: deploy.yml - directory: ${{github.workspace}} + directory: ./ key: ${{secrets.SSH_PRIVATE_KEY}} options: | --inventory hosts From 6bf8287520f863315ac790bdb72d3e224a8bce71 Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Mar 2020 22:32:24 +0100 Subject: [PATCH 7/9] workflows: change default directory to ./ --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4bbe18a..7bf949e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: -v $PWD:/wd \ -w /wd \ -e INPUT_PLAYBOOK="playbook.yml" \ - -e INPUT_DIRECTORY="${{github.workspace}}" \ + -e INPUT_DIRECTORY="./" \ -e INPUT_KEY="${{secrets.SSH_PRIVATE_KEY}}" \ -e INPUT_OPTIONS="--inventory hosts --limit remote" \ action From 7294666400b6d5e17bb1f2085874a9ea1272539a Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Mar 2020 22:43:22 +0100 Subject: [PATCH 8/9] action: remove default value for directory input --- action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 31a55ba..bd5889b 100644 --- a/action.yml +++ b/action.yml @@ -8,9 +8,8 @@ inputs: description: Ansible playbook filepath required: true directory: - description: Root directory of Ansible project + description: Root directory of Ansible project (defaults to current) required: false - default: ./ key: description: SSH private key used to connect to the host required: true From c94ab57c30834eaf8d3c59ada900ea3e02831793 Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Mar 2020 22:44:07 +0100 Subject: [PATCH 9/9] main: don't require directory input to be set --- main.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/main.sh b/main.sh index 6e15928..17a5d37 100755 --- a/main.sh +++ b/main.sh @@ -12,17 +12,14 @@ if test -z "$playbook"; then exit 1 fi -if test -z "$directory"; then - echo "You need to specify 'directory' input (root Ansible project directory)" - exit 1 -fi - if test -z "$key"; then echo "You need to specify 'key' input (SSH private key)" exit 1 fi -cd "$directory" +if test -n "$directory"; then + cd "$directory" +fi mkdir -p "$HOME/.ssh" echo "$key" > "$HOME/.ssh/id_rsa"