mirror of
https://github.com/dawidd6/action-ansible-playbook.git
synced 2026-01-11 14:01:41 -07:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
671974ed60 | ||
|
|
00e2fc8809 | ||
|
|
fbcc2c2bae | ||
|
|
490a9e7da1 | ||
|
|
e959e707d3 | ||
|
|
90a22da2b0 | ||
|
|
aefa1cb082 | ||
|
|
ad014132a3 | ||
|
|
df6f49da3e | ||
|
|
95ac226ed8 | ||
|
|
163a4d1959 | ||
|
|
03f941b221 | ||
|
|
f0b38f33e9 | ||
|
|
75ae627236 | ||
|
|
69990b93b4 | ||
|
|
3c219bf69c |
18
.github/dependabot.yml
vendored
Normal file
18
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: npm
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
|
time: "04:00"
|
||||||
|
pull-request-branch-name:
|
||||||
|
separator: "-"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
|
time: "04:00"
|
||||||
|
pull-request-branch-name:
|
||||||
|
separator: "-"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
7
.github/workflows/test.yml
vendored
7
.github/workflows/test.yml
vendored
@@ -113,3 +113,10 @@ jobs:
|
|||||||
directory: test
|
directory: test
|
||||||
vault_password: test
|
vault_password: test
|
||||||
options: --inventory hosts
|
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`.
|
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
|
- name: Run playbook
|
||||||
uses: dawidd6/action-ansible-playbook@v2
|
uses: dawidd6/action-ansible-playbook@v2
|
||||||
with:
|
with:
|
||||||
|
# Required, playbook filepath
|
||||||
playbook: deploy.yml
|
playbook: deploy.yml
|
||||||
|
# Optional, directory where playbooks live
|
||||||
directory: ./
|
directory: ./
|
||||||
|
# Optional, SSH private key
|
||||||
key: ${{secrets.SSH_PRIVATE_KEY}}
|
key: ${{secrets.SSH_PRIVATE_KEY}}
|
||||||
|
# Optional, literal inventory file contents
|
||||||
inventory: |
|
inventory: |
|
||||||
[all]
|
[all]
|
||||||
example.com
|
example.com
|
||||||
|
|
||||||
[group1]
|
[group1]
|
||||||
example.com
|
example.com
|
||||||
|
# Optional, SSH known hosts file content
|
||||||
|
known_hosts: .known_hosts
|
||||||
|
# Optional, encrypted vault password
|
||||||
vault_password: ${{secrets.VAULT_PASSWORD}}
|
vault_password: ${{secrets.VAULT_PASSWORD}}
|
||||||
|
# Optional, galaxy requirements filepath
|
||||||
|
requirements: galaxy-requirements.yml
|
||||||
|
# Optional, additional flags to pass to ansible-playbook
|
||||||
options: |
|
options: |
|
||||||
|
--inventory .hosts
|
||||||
--limit group1
|
--limit group1
|
||||||
--extra-vars hello=there
|
--extra-vars hello=there
|
||||||
--verbose
|
--verbose
|
||||||
|
|||||||
@@ -28,6 +28,15 @@ inputs:
|
|||||||
options:
|
options:
|
||||||
description: Extra options that should be passed to ansible-playbook command
|
description: Extra options that should be passed to ansible-playbook command
|
||||||
required: false
|
required: false
|
||||||
|
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:
|
runs:
|
||||||
using: node12
|
using: node12
|
||||||
main: main.js
|
main: main.js
|
||||||
|
|||||||
33
main.js
33
main.js
@@ -14,6 +14,8 @@ async function main() {
|
|||||||
const vaultPassword = core.getInput("vault_password")
|
const vaultPassword = core.getInput("vault_password")
|
||||||
const knownHosts = core.getInput("known_hosts")
|
const knownHosts = core.getInput("known_hosts")
|
||||||
const options = core.getInput("options")
|
const options = core.getInput("options")
|
||||||
|
const sudo = core.getInput("sudo")
|
||||||
|
const noColor = core.getInput("no_color")
|
||||||
|
|
||||||
let cmd = ["ansible-playbook", playbook]
|
let cmd = ["ansible-playbook", playbook]
|
||||||
|
|
||||||
@@ -68,23 +70,34 @@ async function main() {
|
|||||||
const knownHostsFile = ".ansible_known_hosts"
|
const knownHostsFile = ".ansible_known_hosts"
|
||||||
fs.writeFileSync(knownHostsFile, knownHosts, { mode: 0600 })
|
fs.writeFileSync(knownHostsFile, knownHosts, { mode: 0600 })
|
||||||
core.saveState("knownHostsFile", knownHostsFile)
|
core.saveState("knownHostsFile", knownHostsFile)
|
||||||
let known_hosts_param = [
|
cmd.push(`--ssh-common-args="-o UserKnownHostsFile=${knownHostsFile}"`)
|
||||||
"--ssh-common-args=",
|
|
||||||
"\"",
|
|
||||||
"-o UserKnownHostsFile=",
|
|
||||||
knownHostsFile,
|
|
||||||
"\""
|
|
||||||
].join('')
|
|
||||||
cmd.push(known_hosts_param)
|
|
||||||
process.env.ANSIBLE_HOST_KEY_CHECKING = "True"
|
process.env.ANSIBLE_HOST_KEY_CHECKING = "True"
|
||||||
} else {
|
} else {
|
||||||
process.env.ANSIBLE_HOST_KEY_CHECKING = "False"
|
process.env.ANSIBLE_HOST_KEY_CHECKING = "False"
|
||||||
}
|
}
|
||||||
|
|
||||||
process.env.ANSIBLE_FORCE_COLOR = "True"
|
if (sudo) {
|
||||||
|
cmd.unshift("sudo", "-E", "env", `PATH=${process.env.PATH}`)
|
||||||
|
}
|
||||||
|
|
||||||
await exec.exec(cmd.join(' '))
|
if (noColor) {
|
||||||
|
process.env.ANSIBLE_NOCOLOR = "True"
|
||||||
|
} else {
|
||||||
|
process.env.ANSIBLE_FORCE_COLOR = "True"
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
} catch (error) {
|
||||||
core.setFailed(error.message)
|
core.setFailed(error.message)
|
||||||
}
|
}
|
||||||
|
|||||||
14
package-lock.json
generated
14
package-lock.json
generated
@@ -5,15 +5,15 @@
|
|||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.7",
|
||||||
"@actions/exec": "^1.0.4",
|
"@actions/exec": "^1.0.4",
|
||||||
"yaml": "^1.10.2"
|
"yaml": "^1.10.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
"version": "1.2.6",
|
"version": "1.2.7",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.7.tgz",
|
||||||
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
|
"integrity": "sha512-kzLFD5BgEvq6ubcxdgPbRKGD2Qrgya/5j+wh4LZzqT915I0V3rED+MvjH6NXghbvk1MXknpNNQ3uKjXSEN00Ig=="
|
||||||
},
|
},
|
||||||
"node_modules/@actions/exec": {
|
"node_modules/@actions/exec": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
@@ -39,9 +39,9 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.2.6",
|
"version": "1.2.7",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.7.tgz",
|
||||||
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
|
"integrity": "sha512-kzLFD5BgEvq6ubcxdgPbRKGD2Qrgya/5j+wh4LZzqT915I0V3rED+MvjH6NXghbvk1MXknpNNQ3uKjXSEN00Ig=="
|
||||||
},
|
},
|
||||||
"@actions/exec": {
|
"@actions/exec": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "action-ansible-playbook",
|
"name": "action-ansible-playbook",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.7",
|
||||||
"@actions/exec": "^1.0.4",
|
"@actions/exec": "^1.0.4",
|
||||||
"yaml": "^1.10.2"
|
"yaml": "^1.10.2"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user