sr2c.podman.podman_curl module – Make an HTTP request with curl from inside a running Podman container
Note
This module is part of the sr2c.podman collection (version 0.0.1).
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install sr2c.podman.
To use it in a playbook, specify: sr2c.podman.podman_curl.
New in sr2c.podman 0.0.1
Synopsis
Runs
curlinside a running container withpodman exec, so a service that only listens on a container network (for example OpenSearch onhttps://localhost:9200) can be called without publishing a port on the host.Intended for rootless Podman. Run the task with
become=trueandbecome_userset to the user that owns the container.Credentials, headers and the request body are passed to curl as a config file on stdin, never as command-line arguments, so they don’t show up in
pson the host or inside the container.The container image must include
curl, version 7.x or later.Reports
changedaccording to HTTP semantics. A successful request with a safe method (GET,HEAD,OPTIONS,TRACE) reportschanged=false; any other method reportschanged=true. To override this, register the result and usechanged_when, for example on status or json.
Parameters
Parameter |
Comments |
|---|---|
Request body. With body_format=json, a dict or list is serialised to JSON and a JSON |
|
How to encode body. Choices:
|
|
Path, inside the container, to a CA bundle to verify the server against. |
|
Path, inside the container, to a PEM client certificate for TLS client authentication. For OpenSearch, presenting the admin certificate is the only way to change |
|
Path, inside the container, to the private key for client_cert. |
|
Name or ID of the running container to run curl in. |
|
Extra request headers. Default: |
|
HTTP method. Default: |
|
HTTP status codes that count as success. Default: |
|
Maximum time in seconds for the whole request. Default: |
|
URL as seen from inside the container, for example |
|
Password for HTTP Basic authentication. |
|
Username for HTTP Basic authentication. |
|
Verify the server’s TLS certificate. Set to Choices:
|
Notes
Note
In check mode, only safe methods (
GET,HEAD,OPTIONS,TRACE) are sent; other methods are skipped and reported aschanged.
Examples
- name: Podman CDR Link | AUDIT | Check OpenSearch cluster health
sr2c.podman.podman_curl:
container: zammad-opensearch
url: https://localhost:9200/_cluster/health
url_username: admin
url_password: "{{ podman_link_opensearch_password }}"
validate_certs: false
become: true
become_user: "{{ podman_link_podman_rootless_user }}"
register: _health
- name: Podman CDR Link | PATCH | Map Link agents to a read-only dashboards role
sr2c.podman.podman_curl:
container: zammad-opensearch
url: https://localhost:9200/_plugins/_security/api/rolesmapping/link_agent
method: PUT
url_username: admin
url_password: "{{ podman_link_opensearch_password }}"
validate_certs: false
body:
backend_roles: ["agent"]
status_code: [200, 201]
become: true
become_user: "{{ podman_link_podman_rootless_user }}"
no_log: true
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Response body as text. Returned: when a response was received |
|
Response body parsed as JSON, if it was valid JSON. Returned: when the response body is JSON |
|
True when the request was not sent because of check mode. Returned: always |
|
HTTP status code returned by the server (0 if no response was received). Returned: always |