Allowing user to interact with dynamic inventory script? (to provide CMDB credentials)

Hello,

I’m feeding Ansible 2.0.0.2 dynamic inventory from an enterprise CMDB system.

I’ve worked through two issues already:

I think the last issue is allow the users to authenticate into the CMDB system…

I am trying to set it up so that the user would type their password into STDIN for the dynamic inventory script… what’s strange is that I can enter TWO lines and the first one isn’t passed to the script… what’s going on here?

$ cat test.sh
#!/bin/sh

read -s cmdb_password

pretend to download data from CMDB

cat /tmp/test.json

and let’s see what was entered

echo $cmdb_password > /tmp/test.out
$ ( echo one; echo two) | ansible -i ./test.sh all --list-hosts
hosts (1):
10.10.10.10
$ cat /tmp/test.out
two
$

Question: What happened to “one” ?

I was hoping to use a wrapper that would prompt the user for their CMDB password and then start Ansible so that when they type in their password it would go to the dynamic inventory script.

Best,
-at

To clarify my question, when Ansible calls a dynamic inventory script that reads in a password, for example:

#!/bin/sh

read -s cmdb_password
echo $cmdb_password > /tmp/test.out

cat /tmp/test.json

I find that when I run Ansible, it is waiting for input. I give it a line of input and then it is still waiting for input! Then I give it a second line of input, and then it keeps going. The second line is what gets logged to /tmp/test.out.

What’s going on? Where does the first line go?

Here is how I test:

( echo one; echo two) | ansible -i ./test.sh all --list-hosts

I find the string “two” in my log file /tmp/test.out

Best,
-at