0%

Ansible-part10: net tool module uri

uri is a net tool moudle, which interacts with HTTP and HTTPS web services and supports Digest, Basic and WSSE HTTP authentication mechanisms.

1
2
3
4
5
6
7
8
tasks:
- name: Check that a page returns a status 200
uri:
url: http://www.example.com
return_content: yes
register: this
- debug:
msg: "{{this}}"

look at the output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/net-tools-modules$ ansible-playbook site1.yml 

PLAY [uri] ********************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************************************************
ok: [cube4200]
ok: [ansible-node1]

TASK [Check that a page returns a status 200] *********************************************************************************************************************************************************************************************************
ok: [cube4200]
ok: [ansible-node1]

TASK [debug] ******************************************************************************************************************************************************************************************************************************************
ok: [ansible-node1] => {
"msg": {
"accept_ranges": "bytes",
"age": "478999",
"cache_control": "max-age=604800",
"changed": false,
"connection": "close",
"content": "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.</p>\n <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n",
"content_length": "1256",
"content_type": "text/html; charset=UTF-8",
"cookies": {},
"cookies_string": "",
"date": "Wed, 17 Jun 2020 02:39:51 GMT",
"elapsed": 0,
"etag": "\"3147526947\"",
"expires": "Wed, 24 Jun 2020 02:39:51 GMT",
"failed": false,
"last_modified": "Thu, 17 Oct 2019 07:18:26 GMT",
"msg": "OK (1256 bytes)",
"redirected": false,
"server": "ECS (sjc/4E44)",
"status": 200,
"url": "http://www.example.com",
"vary": "Accept-Encoding",
"x_cache": "HIT"
}
}
ok: [cube4200] => {
"msg": {
"accept_ranges": "bytes",
"age": "478426",
"cache_control": "max-age=604800",
"changed": false,
"connection": "close",
"content": "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.</p>\n <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n",
"content_length": "1256",
"content_type": "text/html; charset=UTF-8",
"cookies": {},
"cookies_string": "",
"date": "Wed, 17 Jun 2020 02:39:50 GMT",
"elapsed": 0,
"etag": "\"3147526947\"",
"expires": "Wed, 24 Jun 2020 02:39:50 GMT",
"failed": false,
"last_modified": "Thu, 17 Oct 2019 07:18:26 GMT",
"msg": "OK (1256 bytes)",
"redirected": false,
"server": "ECS (sjc/4E76)",
"status": 200,
"url": "http://www.example.com",
"vary": "Accept-Encoding",
"x_cache": "HIT"
}
}

PLAY RECAP ********************************************************************************************************************************************************************************************************************************************
ansible-node1 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
cube4200 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Notice: if there is no return_content: yes, the output will only parts of above info.
the status is 200, which means it is normal.