4 Commits

Author SHA1 Message Date
Dawid Dziurla
c65cf629fb action: add post 2020-05-07 11:42:11 +02:00
Dawid Dziurla
6249522d7c add post script 2020-05-07 11:42:11 +02:00
Dawid Dziurla
9fa54a34c7 main: save filenames in state 2020-05-07 11:42:10 +02:00
Dawid Dziurla
4f3ca9bf23 README: clarify OS 2020-05-03 18:04:31 +02:00
4 changed files with 34 additions and 1 deletions

View File

@@ -2,6 +2,8 @@
An action that executes given Ansible playbook on selected hosts.
Should work on any OS, if `ansible-playbook` command is available in `PATH`.
## Usage
```yaml

View File

@@ -25,3 +25,4 @@ inputs:
runs:
using: node12
main: main.js
post: post.js

View File

@@ -2,7 +2,6 @@ const core = require('@actions/core')
const exec = require('@actions/exec')
const fs = require('fs')
const os = require('os')
const path = require('path')
async function main() {
try {
@@ -26,6 +25,7 @@ async function main() {
if (key) {
const keyFile = ".ansible_key"
fs.writeFileSync(keyFile, key + os.EOL, { mode: 0600 })
core.saveState("keyFile", keyFile)
cmd.push("--key-file")
cmd.push(keyFile)
}
@@ -33,6 +33,7 @@ async function main() {
if (inventory) {
const inventoryFile = ".ansible_inventory"
fs.writeFileSync(inventoryFile, inventory, { mode: 0600 })
core.saveState("inventoryFile", inventoryFile)
cmd.push("--inventory-file")
cmd.push(inventoryFile)
}
@@ -40,6 +41,7 @@ async function main() {
if (vaultPassword) {
const vaultPasswordFile = ".ansible_vault_password"
fs.writeFileSync(vaultPasswordFile, vaultPassword, { mode: 0600 })
core.saveState("vaultPasswordFile", vaultPasswordFile)
cmd.push("--vault-password-file")
cmd.push(vaultPasswordFile)
}

28
post.js Normal file
View 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()