json output would be nice
- Dominant language
- Python
- Stars
- 7
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
Following discussions of #17 and #12 I ran into a use case which I think would justify json output.
Turns out ansible supports dynamic inventories determined by invoking scripts, but needs the output of such a script to be in json format:
```
# ansible -i /etc/ansible/hosts.d/cumulus.sh --list-hosts all
[WARNING]: * Failed to parse /etc/ansible/hosts.d/cumulus.sh with script plugin: failed to parse executable inventory script results from /etc/ansible/hosts.d/cumulus.sh: needs to be a json dict
```
If I manually wrap a `nodeattr` invocation in json, I get what I want:
```
# cat /etc/ansible/hosts.d/cumulus.sh
#!/bin/bash
echo '{ "cumulus":["'$(nodeattr -f /etc/genders.d/cumulus.g -c cumulus|sed 's/,/","/g')'"]}'
# ansible -i /etc/ansible/hosts.d/cumulus.sh --list-hosts all
hosts (6):
mgmtsw1
mgmtsw2
mgmtsw3
mgmtsw4
mgmtsw5
mgmtsw6
```
This would be a lot cleaner if I could use `hostlist` to postprocess:
```
#!/bin/bash
nodeattr -f /etc/genders.d/cumulus.g -c cumulus | hostlist -j
```
Such a `-j` option could either add a dummy name (like "hostlist") to the json, e.g.,
```
{ "hostlist": ["host1","host2","host3"] }
```
...or could possibly take a label as an argument: `-j `.
This isn't an urgent priority, but I thought it was a pretty clean example of how other hostname/genders utilities could be retrofitted with a single CLI switch to interact with newer frameworks.
Contributor guide
No contributing guide indexed for this repository
Research direction
The request is exercised through the hostlist CLI in the shown `hostlist -j` pipeline; start by locating its command-line option handling and output paths. Confirm the intended label behavior, then verify that the result is a JSON object Ansible accepts for dynamic inventory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ansible, python
- Domain
- cli, devops
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100