Vars can be defined as expressions referencing other vars. Allows splitting an expression to a reasonable size.
The environment keyword can apply to all tasks of a play. This can reference vars defined anywhere.
module_defaults can also be used to provide a value to use when none is provided. This tends to be helpful for repetitive things like API creds in general. For pip module, gives an alternative of how to provide an --extra-index-url as the module provides a way to add arbitrary arguments.
group_vars/all/creds.yml or wherever you want to define configuration vars.
username: "{{ hashivault_secrets.value.data.USERNAME }}"
token: "{{ hashivault_secrets.value.data.TOKEN }}"
url: https://{{ username }}:{{ token }}@hosting.com/organization
env:
PIP_EXTRA_INDEX_URL: "{{ url }}"
play.yml You did not provide a play, but this is a good place to use play scope keywords that will apply to all tasks. I'll make up a trivial play, adjust to what you are doing:
- hosts: thingapp
environment: "{{ env }}"
module_defaults:
pip:
extra_args: "--extra-index-url {{ url }}"
roles:
- webserver
- pythonapp
roles/pythonapp/tasks/main.yml
- pip:
name: my-internal-package