Core Idea
Modules are the units of code Ansible sends to remote hosts; this note is a working example collection, opening with the URI module for calling web services from plays.
- The URI module in practice, with runnable YAML.
- Modules are how every task ultimately does its work on the target.
URI Module
- name: "Test it! https://localhost:8443/index.xhtml"
delegate_to: localhost
become: false
uri: url: 'https://localhost:8443/index.xhtml'
validate_certs: false
return_content: true
register: this
failed_when: "'Running on ' not in this.content"This Ansible task uses the uri module to test an HTTPS URL and verify its content. It runs locally (delegate_to: localhost) without privilege escalation (become: false).
- Key Properties:
url: The URL to test.validate_certs: Disabled (false) to bypass SSL certificate checks.return_content: Captures the HTTP response content.
- Result Handling:
- Stores the output in the variable
this. - Fails the task if the response content does not contain
'Running on '.
- Stores the output in the variable
Purpose: To verify that a web server or application is running and serving the expected content.