AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

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 ArticlesAnsible get_url: Download Files from URLsAnsible Lookup Plugins: Fetch External Data

Category: security-compliance

Browse all Ansible tutorials · AnsiblePilot Home