Skip to content

Commit

Permalink
Merge pull request #15 from dawidd6/requirements
Browse files Browse the repository at this point in the history
Support installing requirements
  • Loading branch information
dawidd6 authored Dec 10, 2020
2 parents d28d998 + 9a7cbd2 commit 3c534b3
Show file tree
Hide file tree
Showing 65 changed files with 16,056 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ jobs:
uses: ./
with:
playbook: playbook.yml
requirements: requirements.yml
options: |
--inventory hosts
--limit local
- name: Test local
uses: ./
with:
playbook: playbook.yml
requirements: requirements-bundle.yml
options: |
--inventory hosts
--limit local
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
playbook:
description: Ansible playbook filepath
required: true
requirements:
description: Ansible Galaxy requirements filepath
required: false
directory:
description: Root directory of Ansible project (defaults to current)
required: false
Expand Down
16 changes: 16 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const core = require('@actions/core')
const exec = require('@actions/exec')
const yaml = require('yaml')
const fs = require('fs')
const os = require('os')

async function main() {
try {
const playbook = core.getInput("playbook", { required: true })
const requirements = core.getInput("requirements")
const directory = core.getInput("directory")
const key = core.getInput("key")
const inventory = core.getInput("inventory")
Expand All @@ -23,6 +25,20 @@ async function main() {
core.saveState("directory", directory)
}

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])
if (requirementsObject.collections)
await exec.exec("ansible-galaxy", ["collection", "install", "-r", requirements])
}
}

if (key) {
const keyFile = ".ansible_key"
fs.writeFileSync(keyFile, key + os.EOL, { mode: 0600 })
Expand Down
33 changes: 33 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions node_modules/yaml/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions node_modules/yaml/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3c534b3

Please sign in to comment.