Skip to content

[Imprv] Add proxy support to v4 API client modules #900

@george-ghawali

Description

@george-ghawali

Describe the request

Add proxy support to all v4 API client modules, allowing users to connect to Nutanix clusters through HTTP/HTTPS proxies. Proxy configuration can be set via:

  1. Module parameters (highest priority)
  2. Environment variables using either:
    • Shell export command before running the playbook
    • The environment key in the playbook

Supported proxy parameters:

  • https_proxy / HTTPS_PROXY
  • http_proxy / HTTP_PROXY
  • all_proxy / ALL_PROXY
  • no_proxy / NO_PROXY (to bypass proxy for specific hosts)
  • PROXY_USERNAME / proxy_username (for separate proxy authentication)
  • PROXY_PASSWORD / proxy_password (for separate proxy authentication)

Proxy authentication can be configured in two ways:

  1. Embedded in URL: http://username:password@proxy:port (URL-encode special characters)
  2. Separate parameters/variables: proxy_username and proxy_password

Current behaviour

The v4 API clients do not support proxy configuration.

Expected behaviour

Users can configure proxy settings via module parameters or environment variables:

# Option 1: Via module parameters (recommended)
- name: VM playbook
  hosts: localhost
  module_defaults:
    group/nutanix.ncp.ntnx:
      nutanix_host: "{{ pc_ip }}"
      nutanix_username: "{{ pc_username }}"
      nutanix_password: "{{ pc_password }}"
      validate_certs: false
      https_proxy: "http://user:pass%40word@proxy.example.com:8080"
      no_proxy: "localhost,127.0.0.1"
  tasks:
    - name: List VMs through proxy
      nutanix.ncp.ntnx_vms_info_v2:
      register: result
# Option 2: Via shell export command with credentials in URL
export https_proxy="http://user:pass%40word@proxy.example.com:8080"
ansible-playbook your_playbook.yml
# Option 3: Via shell export command with separate credentials
export HTTPS_PROXY="http://proxy.example.com:8080"
export PROXY_USERNAME="user"
export PROXY_PASSWORD="pass@word"
ansible-playbook your_playbook.yml
# Option 4: Via environment key in playbook with credentials in URL
- name: VM playbook
  hosts: localhost
  vars:
    proxy_env:
      HTTPS_PROXY: "http://user:pass%40word@proxy.example.com:8080"
      NO_PROXY: "localhost,127.0.0.1"
  environment: "{{ proxy_env }}"
  tasks:
    - name: Create VM
      nutanix.ncp.ntnx_vms_v2:
        nutanix_host: "{{ pc_ip }}"
        # ... other params
# Option 5: Via environment key in playbook with separate credentials
- name: VM playbook
  hosts: localhost
  vars:
    proxy_env:
      HTTPS_PROXY: "http://proxy.example.com:8080"
      PROXY_USERNAME: "user"
      PROXY_PASSWORD: "pass@word"
      NO_PROXY: "localhost,127.0.0.1"
  environment: "{{ proxy_env }}"
  tasks:
    - name: Create VM
      nutanix.ncp.ntnx_vms_v2:
        nutanix_host: "{{ pc_ip }}"
        # ... other params

Precedence:

  • Configuration source: Module parameters > Playbook environment key > Shell export variables
  • Proxy URL: https_proxy > http_proxy > all_proxy (lowercase checked before uppercase variants)
  • Credentials: URL-embedded credentials take precedence over proxy_username/proxy_password parameters/variables

Metadata

Metadata

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions