Ansible Study Notes - Bulk inspection site URL status
This article was last updated on: July 24, 2024 am
preface
Do not drag mud and water, do not pull things around.
Quick fixes, learn a skill that can be used for the job in five minutes.
Through concrete practical cases, we vividly demonstrate the use of Ansible.
demand
I need to regularly inspect or regularly monitor the availability status of the homepage of all my company’s sites.
Ansible Playbook practical script
check_url_status.yml As follows:
1 | |
Pass ansible-playbook ./check_url_status.yml Yes, the return result is as follows:
Detailed description
- Used here
ansible-playbookto execute, in the form of a choreographed “script”. hosts: localhostTo perform this task on this local machine, you can also specify other machines;serial: 10: Explicitly define the goals of how Ansible executes the current playbook in batchesuri: URI plugin used, reference link:https://docs.ansible.com/ansible/2.9/modules/uri_module.htmlurl: Specific URL address of the site to be inspecteditemandwith_items: Loop batch execution is implemented through these 2 parametersvars: Defines the variables used in the playbook.
Returns json
If you need to return JSON for further processing, you can use JSON CallBack plugin. As follows:
1 | |
Detailed description
ANSIBLE_CALLBACK_WHITELIST=json: Specify Ansible Callback Whitelist as json; Official Callback documentation:https://docs.ansible.com/ansible/2.9/plugins/callback.htmlANSIBLE_STDOUT_CALLBACK: Specifies the standard output takejsonCallback plugin, the output is in JSON format.jsonCallback plugin official documentation:https://docs.ansible.com/ansible/2.9/plugins/callback/json.html- There’s another one
syslog_jsonPlugins:https://docs.ansible.com/ansible/2.9/plugins/callback/syslog_json.html
EOF
Ansible Study Notes - Bulk inspection site URL status
https://e-whisper.com/posts/60396/