Store a reusable proxy mapping in the appropriate group_vars file:

proxy_env:
  http_proxy: http://gateway.example:8080
  https_proxy: http://gateway.example:8080

Apply it to the remote action:

- name: Download the managed artifact
  ansible.builtin.get_url:
    url: https://downloads.example/artifact.txt
    dest: /tmp/artifact.txt
    mode: '0644'
  environment: "{{ proxy_env }}"

For the public artifact example on a route allowing unauthenticated public intermediaries, take candidate HTTP proxy URLs from the HTTP proxy list and set the artifact URL separately. The module receives the environment in its actual execution context; get_url's documented use_proxy can disable environment-derived proxying for an intended direct task. An export in an interactive .bashrc does not guarantee the same inputs. If the task sees an empty mapping, check whether a play variable overrides the inventory value.

Use block/play environment when the same policy should cover more actions as the same user. That scope does not reconfigure controller lookups, filter plug-ins or Ansible's own connections.

Manage persistent login or service preferences separately. The task's environment ends with its action; a later service obtains its environment from its own startup configuration.

Tënë sô zo