I am writing the Ansible playbook to check the URL status for multiple IPs from the hosts file, however, it is not working when I am giving input as a group name, but is working for single IP
Here is my playbook,
- hosts: "{{ hosts }}"
vars_prompt:
- name: "hosts"
prompt: "Please enter the hosts details"
private: no
- name: "port"
prompt: "Please enter the port"
private: no
serial: 1
tasks:
- name: check the url http://{{ hosts }}:{{ port }}/test
uri:
url: "http://{{ hosts }}:{{ port }}/test"
follow_redirects: none
method: GET
register: _result
until: _result.status == 200
My application is running on below Ips and I want to check the url status for all.
[webservers]
10.10.10.10
10.10.10.20
10.10.10.30
10.10.10.40
But it's getting failed with below error.
ansible-playbook test.yml -u test --ask-pass
SSH password:
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
Please enter the hosts details: webservers
Please enter the port: 8080
[WARNING]: Found variable using reserved name: port
PLAY [webservers] ****************************************************************************> ********************************
TASK [Gathering Facts] **********************************************************************************************************
ok: [10.10.10.10]
TASK [http://webservers:8080/test] **********************************************************************
[WARNING]: The value True (type bool) in a string field was converted to u'True' (type string). If this does not look like what
you expect, quote the entire value to ensure it does not change.
fatal: [10.10.10.10]: FAILED! => {"changed": false, "content": "", "elapsed": 0, "failed_when_result": true, "msg": "Status code was -1 and not [200]: Request failed: <urlopen error [Errno -2] Name or service not known>", "redirected": false, "status": -1, "url": "http://webservers:8080/test"}
PLAY RECAP **********************************************************************************************************************
10.10.10.10 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Can someone please suggest on this?
Thanks!