#36 merge-standard-inventory script to run and merge output from the default standard inventory scripts
Merged by stefw. Opened by merlinm.
Unknown source master

Download 36.patch

The plan is to install the new script to /usr/bin/merge-standard-inventory so it appears in the default $PATH.

See the README.md file added by this PR for a full description of the script and how to use it.

I would suggest wrapping this line at a column width of 70 characters so it is readable in every text editor. Ditto for the line below.

Again, I would suggest wrapping this at around 70 characters so it is readable in a text editor.

argparse is not used by this script

The intent with Ansible is to treat everything that's marked +x executable as an inventory script in this directory. Do you think we could have the same behavior here? If so, we could remove the ignore extensions stuff above and simplify this.

The intent of the tty stuff here is that any stderr output of the above scripts (inventory scripts, etc) goes to the tty (when present). Otherwise Ansible hides this stuff. So I think this opening of the tty stuff and duping to fd 2 needs to happen before forking. Or am I confused here?

This makes this script only work with the standard roles inventory. That's fine. Maybe worth a comment here that "subjects" and "localhost" are expected from standard-test-roles dynamic inventory scripts.

Inventory scripts are expected to take a --list and --host argument. Should we take those arguments and pass them through to the scripts that we invoke?

The intent with Ansible is to treat everything that's marked +x executable as an inventory script in this directory. Do you think we could have the same behavior here? If so, we could remove the ignore extensions stuff above and simplify this.

Adding an executable check on the scripts is a good idea. But the inventory_ignore_extensions stuff is borrowed straight from ansible (http://docs.ansible.com/ansible/latest/intro_dynamic_inventory.html#using-inventory-directories-and-multiple-inventory-sources) and I really think it should stay.

Inventory scripts are expected to take a --list and --host argument. Should we take those arguments and pass them through to the scripts that we invoke?

Indeed. It's already doing that. It simply passes along the exact arguments it is given to each of the scripts it runs.

The intent of the tty stuff here is that any stderr output of the above scripts (inventory scripts, etc) goes to the tty (when present). Otherwise Ansible hides this stuff. So I think this opening of the tty stuff and duping to fd 2 needs to happen before forking. Or am I confused here?

Hmmm. That might explain some oddness I experienced. I'll look into that.

1 new commit added

  • Updates to address review feedback.

Tested by changing the sed repo like so:

diff --git a/inventory b/inventory
index aeb9a12..b118a5a 100755
--- a/inventory
+++ b/inventory
@@ -1,3 +1,3 @@
 #!/bin/bash
 export TEST_DOCKER_EXTRA_ARGS="--privileged"
-exec ./merge-standard-inventory "$@"
+exec merge-standard-inventory "$@"
diff --git a/merge-standard-inventory b/merge-standard-inventory
deleted file mode 100755
index 3b460dc..0000000
--- a/merge-standard-inventory
+++ /dev/null
...

And then:

# cd /path/to/upstreamfirst/sed
# export TEST_SUBJECTS=docker:docker.io/library/fedora:26
# export ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory)
# echo $ANSIBLE_INVENTORY
inventory
# TEST_DEBUG=1 ansible-playbook -t container tests.yml
...
# docker exec -ti gifted_wing /bin/bash
[root@199c25900bbc /]# ls /dev/
autofs           mapper              stdin   tty36  tty9    uhid
bsg              mcelog              stdout  tty37  ttyS0   uinput
btrfs-control    mei0                tty     tty38  ttyS1   urandom
...

And:

# cd /path/to/upstreamfirst/sed
# export TEST_SUBJECTS=../atomic.qcow2
# TEST_DEBUG=1 ansible-playbook -t atomic tests.yml
# echo $?
0

Pull-Request has been merged by stefw

Metadata