From 03f941b22108e0b7dc814be77086c27fa2859ba1 Mon Sep 17 00:00:00 2001 From: obbiondo <45012063+obbiondo@users.noreply.github.com> Date: Mon, 19 Jul 2021 17:49:48 +0200 Subject: [PATCH] Add sudo option for root access (#16) Co-authored-by: ANDREA BIONDO s291512 Co-authored-by: Dawid Dziurla --- action.yml | 3 +++ main.js | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 9766694..c35442d 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,9 @@ inputs: options: description: Extra options that should be passed to ansible-playbook command required: false + sudo: + description: Set to "true" if root is required for running your playbook + required: false runs: using: node12 main: main.js diff --git a/main.js b/main.js index 1789e5e..ddb1af9 100644 --- a/main.js +++ b/main.js @@ -14,6 +14,7 @@ async function main() { const vaultPassword = core.getInput("vault_password") const knownHosts = core.getInput("known_hosts") const options = core.getInput("options") + const sudo = core.getInput("sudo") let cmd = ["ansible-playbook", playbook] @@ -81,10 +82,13 @@ async function main() { process.env.ANSIBLE_HOST_KEY_CHECKING = "False" } + if (sudo) { + cmd.unshift("sudo") + } + process.env.ANSIBLE_FORCE_COLOR = "True" await exec.exec(cmd.join(' ')) - } catch (error) { core.setFailed(error.message) }