It's pretty-much insane to continuously duplicate the behavior (and bugs) of Ansible's inventory script plugin, with scripts/merge-standard-inventory. After speaking with @astepano on this, my understanding is this script is only needed for testing purposes. Otherwise, Ansible itself is always/ultimately responsible for merging all inventory sources.
script
scripts/merge-standard-inventory
Fortunately, Ansible 2.4 obsoletes scripts/merge-standard-inventory (with a new command-line tool)[https://docs.ansible.com/ansible/2.4/ansible-inventory.html].
Unless I'm misunderstanding things, this means merge-standard-inventory can simply be a wrapper around that tool. If otherwise, somebody please clarify my understanding.
merge-standard-inventory
After speaking with @astepano on this, my understanding is this script is only needed for testing purposes.
We need this script when user wants to make some preparations before tests run. Export some environment variable, for example.
Check at: https://pagure.io/standard-test-roles/blob/master/f/scripts/README.md
But, I very like your idea.
I made same tests. For me it looks like ansible-inventory works in the same way as merge-standard-inventory. At lest we can replace one with another.
ansible-inventory
sudo TEST_DEBUG=1 TEST_SUBJECTS=/home/fedora/Fedora-Atomic-27-1.6.x86_64.qcow2 ansible-inventory -i /usr/share/ansible/inventory --list Launching virtual machine for /home/fedora/Fedora-Atomic-27-1.6.x86_64.qcow2 { "_meta": { "hostvars": { "/home/fedora/Fedora-Atomic-27-1.6.x86_64.qcow2": { "ansible_ssh_common_args": "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no", "ansible_ssh_host": "127.0.0.3", "ansible_ssh_pass": "foobar", "ansible_ssh_port": "2223", "ansible_ssh_private_key_file": "/tmp/inventory-cloudnvaCYB/identity", "ansible_ssh_user": "root" } } }, "all": { "children": [ "localhost", "subjects", "ungrouped" ] }, "localhost": { "hosts": [ "/home/fedora/Fedora-Atomic-27-1.6.x86_64.qcow2" ] }, "subjects": { "hosts": [ "/home/fedora/Fedora-Atomic-27-1.6.x86_64.qcow2" ] }, "ungrouped": {} } /home/fedora/file [git::master *] [fedora@f26-box] [11:38] > Either parent process or VM process is gone. DIAGNOSE: ssh -p 2223 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@127.0.0.3 # password: foobar DIAGNOSE: export ANSIBLE_INVENTORY=/tmp/inventory-cloudnvaCYB/inventory DIAGNOSE: kill 19234 # when finished
Metadata Update from @astepano: - Issue assigned to astepano
Ahh okay, good, I'm glad it's not used as part of automation. Yeah, would be nice to just use the ansible-command, it's much less code to maintain here :smile:
Somewhat related...I heard through the grapevine that Ansaible is developing a "runner" - a kind of playbook-execution coordinator. Like a "lite" version of Ansible Tower, for the command-line, with an API. Just in case somebody here was thinking of implementing that next :smile:
Hi
with: #163 it works. But there is a warning:
[WARNING]: Found both group and host with same name: ungrouped [WARNING]: Found both group and host with same name: subjects [WARNING]: Found both group and host with same name: localhost
merge-standard-inventory --list { "_meta": { "hostvars": {} }, "all": { "children": [ "localhost", "subjects", "ungrouped" ] }, "localhost": {}, "subjects": {}, "ungrouped": {} }
I cannot explain why ansible-inventory produces such output... when we have:
/usr/share/ansible/inventory/standard-inventory-local --list { "subjects": { "hosts": [], "vars": {} }, "_meta": { "hostvars": {} }, "localhost": { "hosts": [], "vars": {} }
But seems it is OK:
ansible-inventory -i /usr/share/ansible/inventory/standard-inventory-local --graph @all: |--@localhost: |--@subjects: |--@ungrouped:
ACK to merge it.
Inventory should never provide a group called 'localhost' or 'ungrouped'. Both are handled specially/internally by ansible.
The warning about a host and subject called subjects is more concerning, but maybe an artifact of how it was tested.
subjects
Clarification: Inventory may provide a host definition for localhost, though that can be problematic WRT hosts: all plays.
localhost
hosts: all
Agree, but this is a part of historical legacy. We need to go away from localhost host + group.
Fixed in #163
Metadata Update from @astepano: - Issue close_status updated to: SOLVED - Issue status updated to: Closed (was: Open)
Metadata Update from @astepano: - Issue status updated to: Open (was: Closed)
I reverted my changed https://pagure.io/standard-test-roles/c/aa63b0940d7aadfe532b932b600002ffd19a467d?branch=master
There is a cleanup code in /usr/share/ansible/inventory/standard-inventory-* files. This cleanup code is triggered by monitoring parent pid.
There is no way to keep running ansible-inventory. It exits immediately
Perhaps wrap it it a polling loop with subprocess.check_output(), then it'll run as long as needed :smile:
subprocess.check_output()
Login to comment on this ticket.