Ansible uri Module: Make HTTP Requests and API Calls (Complete Guide)
By Luca Berton · Published 2024-01-01 · Category: security-compliance
How to use Ansible uri module for HTTP GET, POST, PUT, DELETE requests. Call REST APIs, check health endpoints, download JSON. Complete guide with examples.
Ansible uri Module: Make HTTP Requests and API Calls (Complete Guide)
The ansible.builtin.uri module interact with HTTP/HTTPS web services. This guide covers all common use cases with practical playbook examples.
GET Request
POST Request
Health Check with Retries
Download a File
PUT and DELETE
Handle Authentication
FAQ
How do I make HTTP requests in Ansible?
Use ansible.builtin.uri with url, method, and optional body. It supports GET, POST, PUT, DELETE, PATCH, and all HTTP methods. Use return_content: true to capture response body.
How do I call a REST API from Ansible?
Use ansible.builtin.uri with body_format: json and authentication headers. Register the response to use API data in subsequent tasks. Use retries for resilient API calls.
What is the difference between uri and get_url modules?
uri is for API interactions (any HTTP method, response parsing). get_url is specifically for downloading files to disk. Use uri for APIs, get_url for file downloads.
Conclusion
The ansible.builtin.uri module is a versatile tool for interact with HTTP/HTTPS web services. Use the examples above as starting points and adapt them to your infrastructure needs.
Related Articles • Ansible get_url: Download Files from URLs • Ansible Lookup Plugins: Fetch External Data
Category: security-compliance