Add check mode option

This commit is contained in:
Alex van den Hoogen 2025-02-10 10:06:28 +01:00
parent 245b181622
commit 95b662c1c8
3 changed files with 15 additions and 0 deletions

View File

@ -97,6 +97,13 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 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 - name: With custom ansible.cfg
uses: ./ uses: ./
with: with:

View File

@ -37,6 +37,9 @@ inputs:
no_color: no_color:
description: Set to "true" if the Ansible output should not include colors (defaults to "false") description: Set to "true" if the Ansible output should not include colors (defaults to "false")
required: false required: false
check_mode:
description: Set to "true" to enable check (dry-run) mode
required: false
outputs: outputs:
output: output:
description: The captured output of both stdout and stderr from the Ansible Playbook run description: The captured output of both stdout and stderr from the Ansible Playbook run

View File

@ -17,6 +17,7 @@ async function main() {
const options = core.getInput("options") const options = core.getInput("options")
const sudo = core.getInput("sudo") const sudo = core.getInput("sudo")
const noColor = core.getInput("no_color") const noColor = core.getInput("no_color")
const checkMode = core.getInput("check_mode")
const fileMode = 0600 const fileMode = 0600
let cmd = ["ansible-playbook", playbook] let cmd = ["ansible-playbook", playbook]
@ -94,6 +95,10 @@ async function main() {
process.env.ANSIBLE_FORCE_COLOR = "True" process.env.ANSIBLE_FORCE_COLOR = "True"
} }
if (checkMode) {
cmd.push("--check")
}
let output = "" let output = ""
await exec.exec(cmd.join(' '), null, { await exec.exec(cmd.join(' '), null, {
listeners: { listeners: {