1
0
Fork 0
mirror of https://github.com/dawidd6/action-ansible-playbook.git synced 2024-11-22 15:32:18 +00:00

main: parse requirements yaml and run appropriate commands

This commit is contained in:
Dawid Dziurla 2020-12-09 11:57:43 +01:00
parent 19d1b2c628
commit 9a7cbd2b6b
No known key found for this signature in database
GPG key ID: 7B6D8368172E9B0B

10
main.js
View file

@ -1,5 +1,6 @@
const core = require('@actions/core') const core = require('@actions/core')
const exec = require('@actions/exec') const exec = require('@actions/exec')
const yaml = require('yaml')
const fs = require('fs') const fs = require('fs')
const os = require('os') const os = require('os')
@ -25,9 +26,18 @@ async function main() {
} }
if (requirements) { if (requirements) {
const requirementsContent = fs.readFileSync(requirements, 'utf8')
const requirementsObject = yaml.parse(requirementsContent)
if (Array.isArray(requirementsObject)) {
await exec.exec("ansible-galaxy", ["install", "-r", requirements])
} else {
if (requirementsObject.roles)
await exec.exec("ansible-galaxy", ["role", "install", "-r", requirements]) await exec.exec("ansible-galaxy", ["role", "install", "-r", requirements])
if (requirementsObject.collections)
await exec.exec("ansible-galaxy", ["collection", "install", "-r", requirements]) await exec.exec("ansible-galaxy", ["collection", "install", "-r", requirements])
} }
}
if (key) { if (key) {
const keyFile = ".ansible_key" const keyFile = ".ansible_key"