.. _vyos.rest.vyos_httpapi: ************** vyos.rest.vyos ************** **HttpApi plugin for VyOS REST API** Version added: 1.0.0 .. contents:: :local: :depth: 1 Synopsis -------- - This HttpApi plugin provides methods to connect to VyOS devices via their HTTPS REST API. - Use with ``ansible_connection=ansible.netcommon.httpapi`` and ``ansible_network_os=vyos.rest.vyos``. - The VyOS REST API must be enabled with ``set service https api keys id ansible key YOUR_KEY``, ``set service https api rest``, then ``commit && save``. Parameters ---------- .. raw:: html
Parameter Choices/Defaults Configuration Comments
api_key
string
env:VYOS_API_KEY
var: ansible_httpapi_api_key
var: ansible_vyos_api_key
The API key configured on the VyOS device.
Set ansible_httpapi_api_key in inventory or the VYOS_API_KEY environment variable.
auth_method
string
    Choices:
  • key ←
  • header
  • bearer
  • mtls
  • oidc
var: ansible_httpapi_vyos_auth_method
var: ansible_vyos_auth_method
Authentication method to use.
key sends the API key as a form field (default, backward-compatible).
header sends the API key as an X-API-Key header.
bearer exchanges the API key for a short-lived JWT via POST /token and sends it as an Authorization Bearer header for subsequent requests.
mtls uses mutual TLS client certificate authentication. No API key is sent. Requires ansible_httpapi_client_cert and ansible_httpapi_client_key to be set at the connection level.
oidc fetches a Bearer token from an external identity provider using the OAuth2 client credentials grant and sends it as an Authorization Bearer header. Requires ansible_vyos_oidc_token_url, ansible_vyos_oidc_client_id, and ansible_vyos_oidc_client_secret.
oidc_client_id
string
var: ansible_vyos_oidc_client_id
OAuth2 client ID for the client credentials grant.
Required when auth_method=oidc.
oidc_client_secret
string
var: ansible_vyos_oidc_client_secret
OAuth2 client secret for the client credentials grant.
Required when auth_method=oidc.
oidc_token_url
string
var: ansible_vyos_oidc_token_url
Full URL of the OAuth2/OIDC token endpoint.
Required when auth_method=oidc.

Notes ----- .. note:: - Bearer tokens are cached in memory for the duration of the connection and refreshed automatically 30 seconds before expiry. - Token expiry is controlled on the device via ``set service https api rest authentication expiration ``. - For mTLS, set ``ansible_httpapi_client_cert`` and ``ansible_httpapi_client_key`` at the connection level. The netcommon httpapi connection plugin handles the TLS handshake automatically. - OIDC tokens are cached and refreshed using the ``expires_in`` value returned by the identity provider. Examples -------- .. code-block:: yaml # inventory.yml - form-field API key (default, backward-compatible) all: hosts: vyos01: ansible_host: 192.168.1.1 ansible_connection: ansible.netcommon.httpapi ansible_network_os: vyos.rest.vyos ansible_httpapi_use_ssl: true ansible_httpapi_validate_certs: false ansible_httpapi_api_key: mysecretkey # inventory.yml - X-API-Key header all: hosts: vyos01: ansible_host: 192.168.1.1 ansible_connection: ansible.netcommon.httpapi ansible_network_os: vyos.rest.vyos ansible_httpapi_use_ssl: true ansible_httpapi_validate_certs: false ansible_httpapi_api_key: mysecretkey ansible_vyos_auth_method: header # inventory.yml - Bearer token (JWT) all: hosts: vyos01: ansible_host: 192.168.1.1 ansible_connection: ansible.netcommon.httpapi ansible_network_os: vyos.rest.vyos ansible_httpapi_use_ssl: true ansible_httpapi_validate_certs: false ansible_httpapi_api_key: mysecretkey ansible_vyos_auth_method: bearer # inventory.yml - mTLS client certificate all: hosts: vyos01: ansible_host: 192.168.1.1 ansible_connection: ansible.netcommon.httpapi ansible_network_os: vyos.rest.vyos ansible_httpapi_use_ssl: true ansible_httpapi_validate_certs: false ansible_vyos_auth_method: mtls ansible_httpapi_client_cert: /etc/ansible/certs/client.pem ansible_httpapi_client_key: /etc/ansible/certs/client.key # inventory.yml - OIDC (Keycloak client credentials) all: hosts: vyos01: ansible_host: 192.168.1.1 ansible_connection: ansible.netcommon.httpapi ansible_network_os: vyos.rest.vyos ansible_httpapi_use_ssl: true ansible_httpapi_validate_certs: false ansible_vyos_auth_method: oidc ansible_vyos_oidc_token_url: https://keycloak.example.com/realms/vyos/protocol/openid-connect/token ansible_vyos_oidc_client_id: vyos-api ansible_vyos_oidc_client_secret: mysecret Status ------ Authors ~~~~~~~ - VyOS Community (@vyos) .. hint:: Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.