9 Commits

Author SHA1 Message Date
Dawid Dziurla
e3e388ffee Merge pull request #7 from dawidd6/dawidd6-patch-1
Fix directory handling in post run
2020-05-14 20:27:25 +02:00
Dawid Dziurla
12b09931f9 workflows: test directory 2020-05-14 20:20:43 +02:00
Dawid Dziurla
6f709ceecd add directory test playbook 2020-05-14 20:19:22 +02:00
Dawid Dziurla
89ee60634c post: change directory if saved 2020-05-14 20:16:43 +02:00
Dawid Dziurla
83c93acd55 main: save directory to state 2020-05-14 20:13:55 +02:00
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
6 changed files with 47 additions and 2 deletions

View File

@@ -23,7 +23,7 @@ jobs:
uses: ./ uses: ./
with: with:
playbook: playbook.yml playbook: playbook.yml
directory: ./ directory: test
key: ${{secrets.SSH_PRIVATE_KEY}} key: ${{secrets.SSH_PRIVATE_KEY}}
inventory: | inventory: |
[all] [all]

View File

@@ -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

View File

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

View File

@@ -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 {
@@ -21,11 +20,13 @@ async function main() {
if (directory) { if (directory) {
process.chdir(directory) process.chdir(directory)
core.saveState("directory", directory)
} }
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 +34,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 +42,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)
} }

32
post.js Normal file
View File

@@ -0,0 +1,32 @@
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 directory = core.getState("directory")
const keyFile = core.getState("keyFile")
const inventoryFile = core.getState("inventoryFile")
const vaultPasswordFile = core.getState("vaultPasswordFile")
if (directory)
process.chdir(directory)
if (keyFile)
rm(keyFile)
if (inventoryFile)
rm(inventoryFile)
if (vaultPasswordFile)
rm(vaultPasswordFile)
} catch (error) {
core.setFailed(error.message)
}
}
main()

7
test/playbook.yml Normal file
View File

@@ -0,0 +1,7 @@
- name: Test Action
hosts: all
tasks:
- name: Copy action.yml
copy:
src: ../action.yml
dest: /tmp/action.yml