1
0
Fork 0
mirror of https://github.com/dawidd6/action-ansible-playbook.git synced 2024-12-22 20:32:34 +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

14
main.js
View file

@ -1,5 +1,6 @@
const core = require('@actions/core')
const exec = require('@actions/exec')
const yaml = require('yaml')
const fs = require('fs')
const os = require('os')
@ -25,8 +26,17 @@ async function main() {
}
if (requirements) {
await exec.exec("ansible-galaxy", ["role", "install", "-r", requirements])
await exec.exec("ansible-galaxy", ["collection", "install", "-r", 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])
if (requirementsObject.collections)
await exec.exec("ansible-galaxy", ["collection", "install", "-r", requirements])
}
}
if (key) {