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

91 views
Skip to first unread message

Aleksey Tsalolikhin

unread,
Apr 14, 2016, 10:09:01 AM4/14/16
to Ansible Project
Hello,

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

I've worked through two issues already:

- inject empty _meta hostvars to be able to read in large JSON objects without killing RAM & CPU  (https://groups.google.com/forum/#!searchin/Ansible-project/tsalolikhin/ansible-project/AB997vCLtCY/MT3CxG-fCAAJ)
- filter CMDB output to remove records that don't have IP addresses as it makes Ansible throw Python errors

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

Aleksey Tsalolikhin

unread,
Apr 21, 2016, 3:58:55 PM4/21/16
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages