Background
I have domain managed via Terraform and it outputs server IP address. Then I have a script which outputs YAML inventory (outputs follows later).
- Ansible 2.6.2
- Source of format: https://docs.ansible.com/ansible/2.6/user_guide/intro_inventory.html#hosts-and-groups
Problem
When I run ansible-inventory --inventory inventory.sh --graph
it always end up with
@all:
|--@stage:
|--@ungrouped:
| |--18.66.1.28
Were I would expect the machine to be in group stage.
I found out there is different behaviour for static inventory and for inventory as a script output.
Static file
If You save this as a static file and use it as an inventory, it will work.
all:
hosts:
18.66.1.28
children:
stage:
hosts:
18.66.1.28:
Output:
@all:
|--@stage:
| |--18.66.1.28
|--@ungrouped:
Script
but if You specify shell script like follows, it won't work
#!/bin/bash
echo "all:
hosts:
18.66.1.28
children:
stage:
hosts:
18.66.1.28:"
Output:
[WARNING]: * Failed to parse /tmp/inventory.sh with script plugin: You defined a group 'all' with bad data for the host list: {u'hosts':
u'18.66.1.28', u'children': {u'stage': {u'hosts': {u'18.66.1.28': None}}}}
[WARNING]: * Failed to parse /tmp/inventory.sh with ini plugin: /tmp/inventory.sh:3: Error parsing host definition 'echo "all:': No closing
quotation
[WARNING]: Unable to parse /tmp/inventory.sh as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
YAML outputs
Variant 1
all:
hosts:
- 18.66.1.28
children:
stage:
hosts:
- 18.66.1.28:
Variant 2
all:
hosts:
- 18.66.1.28
children:
stage:
hosts:
18.66.1.28:
Variant 3
all:
hosts:
- 18.66.1.28
children:
stage:
hosts:
- 18.66.1.28