host_list cannot accept a JSON string. It expects either a CSV string of hosts, the path to an INI formatted file, or a path to a script that can be executed to return the JSON you are trying to pass directly to host_list.
On Tuesday, June 14, 2016, Idan null <[email protected]> wrote: > Hello to everyone :) > I'm quite new to Ansible. > I have used the Python API for ansible to connect to a few servers I have, > I want to get the inventory list for the python script from MySQL server, > so as far as I understood the list should be in Json format (this is > because each host have different ports) > But when I run the script I get a error that ansible couldn't connect to > the server: > > This is the error i'm getting: > UP *********** > FAILED ******* > DOWN ********* > { > "_meta": { > "hostvars": { > "10.24.20.126": { > "ansible_host": "10.24.20.126" >>> Failed to connect to the host > via ssh. > > This is the full json I'm sending to the host_list variable in the python > script > js = {"group": {"hosts": ["10.24.20.126", "10.24.20.127"], "vars": > {"ansible_user": "user", "ansible_port": 22}}, "_meta": {"hostvars": > {"10.24.20.126": {"ansible_host": "10.24.20.126", "ansible_user": "user", > "ansible_port": "22"}, "10.24.20.127": {"host_specific_var": "foo"}}}} > > And this is the error i'm getting: > > UP *********** > FAILED ******* > DOWN ********* > { > "_meta": { > "hostvars": { > "10.24.20.126": { > "ansible_host": "10.24.20.126" >>> Failed to connect to the host > via ssh. > > > This ansible can connect to this server if i ping it using ansible > (ansible -m ping 10.24.20.126) > > 10.24.20.126 | SUCCESS => { > "changed": false, > "ping": "pong" > } > > the python script I took from here: > https://github.com/ansible/ansible/blob/devel/examples/scripts/uptime.py > > And I just send into the host_list variable the JSON. > > Any thought of why my script doesn't work ? > > Thank you evreyone > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <javascript:_e(%7B%7D,'cvml','ansible-project%[email protected]');> > . > To post to this group, send email to [email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/33aa946b-feaa-42f2-8465-567f507b1ced%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/33aa946b-feaa-42f2-8465-567f507b1ced%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Matt Martz @sivel sivel.net -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v_R-E14ZEJbBhv2GsQO8HJrYuowijEp7JQ5BEc%2B99nC%3Dw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
