6 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
Dawid Dziurla
c667c001c3 main: replace all newlines 2020-05-03 12:50:24 +02:00
Dawid Dziurla
013642b2f2 workflows: more options test 2020-05-03 12:45:56 +02:00
5 changed files with 42 additions and 2 deletions

View File

@@ -28,6 +28,13 @@ jobs:
inventory: |
[all]
localhost
options: |
-e docker_image=docker_url
-e docker_username=${{github.actor}}
-e docker_password=${{github.token}}
-e db_name=db_name
-e db_user=db_user
-e db_pass=db_pass
test-local:
runs-on: ubuntu-latest
steps:

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 {
@@ -16,7 +15,7 @@ async function main() {
let cmd = ["ansible-playbook", playbook]
if (options) {
cmd.push(options.replace("\n", " "))
cmd.push(options.replace(/\n/g, " "))
}
if (directory) {
@@ -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()