mirror of
https://github.com/dawidd6/action-ansible-playbook.git
synced 2026-01-11 05:51:42 -07:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3e388ffee | ||
|
|
12b09931f9 | ||
|
|
6f709ceecd | ||
|
|
89ee60634c | ||
|
|
83c93acd55 | ||
|
|
c65cf629fb | ||
|
|
6249522d7c | ||
|
|
9fa54a34c7 | ||
|
|
4f3ca9bf23 | ||
|
|
c667c001c3 | ||
|
|
013642b2f2 |
9
.github/workflows/test.yml
vendored
9
.github/workflows/test.yml
vendored
@@ -23,11 +23,18 @@ jobs:
|
||||
uses: ./
|
||||
with:
|
||||
playbook: playbook.yml
|
||||
directory: ./
|
||||
directory: test
|
||||
key: ${{secrets.SSH_PRIVATE_KEY}}
|
||||
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
|
||||
|
||||
7
main.js
7
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,16 +15,18 @@ async function main() {
|
||||
let cmd = ["ansible-playbook", playbook]
|
||||
|
||||
if (options) {
|
||||
cmd.push(options.replace("\n", " "))
|
||||
cmd.push(options.replace(/\n/g, " "))
|
||||
}
|
||||
|
||||
if (directory) {
|
||||
process.chdir(directory)
|
||||
core.saveState("directory", directory)
|
||||
}
|
||||
|
||||
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 +34,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 +42,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)
|
||||
}
|
||||
|
||||
32
post.js
Normal file
32
post.js
Normal 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
7
test/playbook.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- name: Test Action
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: Copy action.yml
|
||||
copy:
|
||||
src: ../action.yml
|
||||
dest: /tmp/action.yml
|
||||
Reference in New Issue
Block a user