Skip to content

Instantly share code, notes, and snippets.

@chadh
Created October 11, 2019 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadh/8ae7a06f428e2d8b22fc7fe7065185c2 to your computer and use it in GitHub Desktop.
Save chadh/8ae7a06f428e2d8b22fc7fe7065185c2 to your computer and use it in GitHub Desktop.
simple bolt plugin for retrieving inventory from our in-house system DCM
  1. I already had a module with some functions and stuff for our in-house app, DCM, so I just reused that module for this purpose. You could also just make a new, blank module. It should have a bolt_plugin.json file in it to indicate to bolt that the module has a plugin(s)
  2. Create a task to do your lookup. The easiest way is to name it resolve_reference, since that is the name of the hook, and bolt will automatically it. I used bash, but this is just a regular task, so you can use whatever language you want. My example has a single parameter query that I pull off of stdin with jq. The output is a hash with a single key value, and the value for that key is the data that shoudl go in the inventory file.
  3. Add your module to the Puppetfile in your bolt control repo and bolt puppetfile install
  4. Edit your inventory.yaml

I know those are rough instructions, but they should get you started.

---
version: 2
groups:
- name: "puppet"
targets:
- _plugin: dcm
query: "project=puppet"
- name: "stage"
targets:
- _plugin: dcm
query: "env=stage"
{
"puppet_task_version": 1,
"supports_noop": false,
"description": "retrieves bolt inventory from dcm",
"parameters": {
"query": {
"type": "String",
"description": "Query to pass to `dcm search`"
}
}
}
#!/usr/bin/env bash
query=$(jq -r .query)
echo '{ "value": ['
first_time="true"
for i in $(dcm search -t hosts "$query"); do
if [[ $first_time != "true" ]]; then
echo -n ", "
else
first_time="false"
fi
printf '{ "uri": "%s" }' "$i"
done
echo ']}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment