From 95b662c1c8081bded143512e70ea168c4b341e9f Mon Sep 17 00:00:00 2001 From: Alex van den Hoogen Date: Mon, 10 Feb 2025 10:06:28 +0100 Subject: [PATCH] Add check mode option --- .github/workflows/test.yml | 7 +++++++ action.yml | 3 +++ main.js | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 72658c8..c104dc4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -97,6 +97,13 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: With check mode + uses: ./ + with: + playbook: playbook.yml + directory: test + check: true + options: --inventory hosts - name: With custom ansible.cfg uses: ./ with: diff --git a/action.yml b/action.yml index 0371f80..9b15026 100644 --- a/action.yml +++ b/action.yml @@ -37,6 +37,9 @@ inputs: no_color: description: Set to "true" if the Ansible output should not include colors (defaults to "false") required: false + check_mode: + description: Set to "true" to enable check (dry-run) mode + required: false outputs: output: description: The captured output of both stdout and stderr from the Ansible Playbook run diff --git a/main.js b/main.js index 2ad6292..ca862fd 100644 --- a/main.js +++ b/main.js @@ -17,6 +17,7 @@ async function main() { const options = core.getInput("options") const sudo = core.getInput("sudo") const noColor = core.getInput("no_color") + const checkMode = core.getInput("check_mode") const fileMode = 0600 let cmd = ["ansible-playbook", playbook] @@ -94,6 +95,10 @@ async function main() { process.env.ANSIBLE_FORCE_COLOR = "True" } + if (checkMode) { + cmd.push("--check") + } + let output = "" await exec.exec(cmd.join(' '), null, { listeners: {