mirror of
https://github.com/dawidd6/action-ansible-playbook.git
synced 2026-01-11 14:01:41 -07:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c65cf629fb | ||
|
|
6249522d7c | ||
|
|
9fa54a34c7 | ||
|
|
4f3ca9bf23 | ||
|
|
c667c001c3 | ||
|
|
013642b2f2 |
7
.github/workflows/test.yml
vendored
7
.github/workflows/test.yml
vendored
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -25,3 +25,4 @@ inputs:
|
||||
runs:
|
||||
using: node12
|
||||
main: main.js
|
||||
post: post.js
|
||||
|
||||
6
main.js
6
main.js
@@ -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
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