mirror of
https://github.com/dawidd6/action-ansible-playbook.git
synced 2026-01-11 14:01:41 -07:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c65cf629fb | ||
|
|
6249522d7c | ||
|
|
9fa54a34c7 | ||
|
|
4f3ca9bf23 |
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
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`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|||||||
@@ -25,3 +25,4 @@ inputs:
|
|||||||
runs:
|
runs:
|
||||||
using: node12
|
using: node12
|
||||||
main: main.js
|
main: main.js
|
||||||
|
post: post.js
|
||||||
|
|||||||
4
main.js
4
main.js
@@ -2,7 +2,6 @@ const core = require('@actions/core')
|
|||||||
const exec = require('@actions/exec')
|
const exec = require('@actions/exec')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const path = require('path')
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
@@ -26,6 +25,7 @@ async function main() {
|
|||||||
if (key) {
|
if (key) {
|
||||||
const keyFile = ".ansible_key"
|
const keyFile = ".ansible_key"
|
||||||
fs.writeFileSync(keyFile, key + os.EOL, { mode: 0600 })
|
fs.writeFileSync(keyFile, key + os.EOL, { mode: 0600 })
|
||||||
|
core.saveState("keyFile", keyFile)
|
||||||
cmd.push("--key-file")
|
cmd.push("--key-file")
|
||||||
cmd.push(keyFile)
|
cmd.push(keyFile)
|
||||||
}
|
}
|
||||||
@@ -33,6 +33,7 @@ async function main() {
|
|||||||
if (inventory) {
|
if (inventory) {
|
||||||
const inventoryFile = ".ansible_inventory"
|
const inventoryFile = ".ansible_inventory"
|
||||||
fs.writeFileSync(inventoryFile, inventory, { mode: 0600 })
|
fs.writeFileSync(inventoryFile, inventory, { mode: 0600 })
|
||||||
|
core.saveState("inventoryFile", inventoryFile)
|
||||||
cmd.push("--inventory-file")
|
cmd.push("--inventory-file")
|
||||||
cmd.push(inventoryFile)
|
cmd.push(inventoryFile)
|
||||||
}
|
}
|
||||||
@@ -40,6 +41,7 @@ async function main() {
|
|||||||
if (vaultPassword) {
|
if (vaultPassword) {
|
||||||
const vaultPasswordFile = ".ansible_vault_password"
|
const vaultPasswordFile = ".ansible_vault_password"
|
||||||
fs.writeFileSync(vaultPasswordFile, vaultPassword, { mode: 0600 })
|
fs.writeFileSync(vaultPasswordFile, vaultPassword, { mode: 0600 })
|
||||||
|
core.saveState("vaultPasswordFile", vaultPasswordFile)
|
||||||
cmd.push("--vault-password-file")
|
cmd.push("--vault-password-file")
|
||||||
cmd.push(vaultPasswordFile)
|
cmd.push(vaultPasswordFile)
|
||||||
}
|
}
|
||||||
|
|||||||
28
post.js
Normal file
28
post.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const core = require('@actions/core')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
function rm(file) {
|
||||||
|
core.info(`==> Deleting "${file}" file`)
|
||||||
|
fs.unlinkSync(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
const keyFile = core.getState("keyFile")
|
||||||
|
const inventoryFile = core.getState("inventoryFile")
|
||||||
|
const vaultPasswordFile = core.getState("vaultPasswordFile")
|
||||||
|
|
||||||
|
if (keyFile)
|
||||||
|
rm(keyFile)
|
||||||
|
|
||||||
|
if (inventoryFile)
|
||||||
|
rm(inventoryFile)
|
||||||
|
|
||||||
|
if (vaultPasswordFile)
|
||||||
|
rm(vaultPasswordFile)
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed(error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user