mirror of
https://github.com/dawidd6/action-ansible-playbook.git
synced 2026-01-11 14:01:41 -07:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
671974ed60 | ||
|
|
00e2fc8809 | ||
|
|
fbcc2c2bae | ||
|
|
490a9e7da1 | ||
|
|
e959e707d3 | ||
|
|
90a22da2b0 | ||
|
|
aefa1cb082 | ||
|
|
ad014132a3 | ||
|
|
df6f49da3e | ||
|
|
95ac226ed8 | ||
|
|
163a4d1959 |
7
.github/workflows/test.yml
vendored
7
.github/workflows/test.yml
vendored
@@ -113,3 +113,10 @@ jobs:
|
||||
directory: test
|
||||
vault_password: test
|
||||
options: --inventory hosts
|
||||
- name: With sudo
|
||||
uses: ./
|
||||
with:
|
||||
playbook: playbook.yml
|
||||
directory: test
|
||||
sudo: true
|
||||
options: --inventory hosts
|
||||
|
||||
15
README.md
15
README.md
@@ -1,6 +1,6 @@
|
||||
# Run Ansible playbook Github Action
|
||||
# Run Ansible playbook GitHub Action
|
||||
|
||||
An action that executes given Ansible playbook on selected hosts.
|
||||
An Action that executes given Ansible playbook on selected hosts.
|
||||
|
||||
Should work on any OS, if `ansible-playbook` command is available in `PATH`.
|
||||
|
||||
@@ -10,17 +10,28 @@ Should work on any OS, if `ansible-playbook` command is available in `PATH`.
|
||||
- name: Run playbook
|
||||
uses: dawidd6/action-ansible-playbook@v2
|
||||
with:
|
||||
# Required, playbook filepath
|
||||
playbook: deploy.yml
|
||||
# Optional, directory where playbooks live
|
||||
directory: ./
|
||||
# Optional, SSH private key
|
||||
key: ${{secrets.SSH_PRIVATE_KEY}}
|
||||
# Optional, literal inventory file contents
|
||||
inventory: |
|
||||
[all]
|
||||
example.com
|
||||
|
||||
[group1]
|
||||
example.com
|
||||
# Optional, SSH known hosts file content
|
||||
known_hosts: .known_hosts
|
||||
# Optional, encrypted vault password
|
||||
vault_password: ${{secrets.VAULT_PASSWORD}}
|
||||
# Optional, galaxy requirements filepath
|
||||
requirements: galaxy-requirements.yml
|
||||
# Optional, additional flags to pass to ansible-playbook
|
||||
options: |
|
||||
--inventory .hosts
|
||||
--limit group1
|
||||
--extra-vars hello=there
|
||||
--verbose
|
||||
|
||||
@@ -31,6 +31,12 @@ inputs:
|
||||
sudo:
|
||||
description: Set to "true" if root is required for running your playbook
|
||||
required: false
|
||||
no_color:
|
||||
description: Set to "true" if the Ansible output should not include colors (defaults to "false")
|
||||
required: false
|
||||
outputs:
|
||||
output:
|
||||
description: The captured output of both stdout and stderr from the Ansible Playbook run
|
||||
runs:
|
||||
using: node12
|
||||
main: main.js
|
||||
|
||||
31
main.js
31
main.js
@@ -15,6 +15,7 @@ async function main() {
|
||||
const knownHosts = core.getInput("known_hosts")
|
||||
const options = core.getInput("options")
|
||||
const sudo = core.getInput("sudo")
|
||||
const noColor = core.getInput("no_color")
|
||||
|
||||
let cmd = ["ansible-playbook", playbook]
|
||||
|
||||
@@ -69,26 +70,34 @@ async function main() {
|
||||
const knownHostsFile = ".ansible_known_hosts"
|
||||
fs.writeFileSync(knownHostsFile, knownHosts, { mode: 0600 })
|
||||
core.saveState("knownHostsFile", knownHostsFile)
|
||||
let known_hosts_param = [
|
||||
"--ssh-common-args=",
|
||||
"\"",
|
||||
"-o UserKnownHostsFile=",
|
||||
knownHostsFile,
|
||||
"\""
|
||||
].join('')
|
||||
cmd.push(known_hosts_param)
|
||||
cmd.push(`--ssh-common-args="-o UserKnownHostsFile=${knownHostsFile}"`)
|
||||
process.env.ANSIBLE_HOST_KEY_CHECKING = "True"
|
||||
} else {
|
||||
process.env.ANSIBLE_HOST_KEY_CHECKING = "False"
|
||||
}
|
||||
|
||||
if (sudo) {
|
||||
cmd.unshift("sudo")
|
||||
cmd.unshift("sudo", "-E", "env", `PATH=${process.env.PATH}`)
|
||||
}
|
||||
|
||||
process.env.ANSIBLE_FORCE_COLOR = "True"
|
||||
if (noColor) {
|
||||
process.env.ANSIBLE_NOCOLOR = "True"
|
||||
} else {
|
||||
process.env.ANSIBLE_FORCE_COLOR = "True"
|
||||
}
|
||||
|
||||
await exec.exec(cmd.join(' '))
|
||||
let output = ""
|
||||
await exec.exec(cmd.join(' '), null, {
|
||||
listeners: {
|
||||
stdout: function(data) {
|
||||
output += data.toString()
|
||||
},
|
||||
stderr: function(data) {
|
||||
output += data.toString()
|
||||
}
|
||||
}
|
||||
})
|
||||
core.setOutput("output", output)
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user