kayobe/ansible/roles/pip/tasks/pip_conf.yml
Mark Goddard 43650cb966 Performance: refactor pip configuration
Currently we perform pip configuration for a list of users, including
pip_conf.yml in a loop for each user. It is slightly more efficient to
loop over each task, since individual tasks have a higher overhead than
loops.

This change refactors the code into multiple loops, with a single
include. We keep the include to allow skipping the tasks when pip
configuration is not required.

Change-Id: I698d38613f45bd03a2e51572f6e6fb69e934f614
Story: 2007993
Task: 40719
2020-08-24 10:29:02 +01:00

41 lines
1000 B
YAML

---
- name: Create local .pip directory
file:
path: "~{{ item }}/.pip"
state: directory
become: True
become_user: "{{ item }}"
loop: "{{ pip_applicable_users }}"
- name: Create pip.conf
copy:
content: |
[global]
{% if pip_index_url | length > 0 -%}
index-url = {{ pip_index_url }}
{% endif -%}
{% if pip_trusted_hosts | length > 0 -%}
trusted-host =
{% for host in pip_trusted_hosts | unique -%}
{{ host }}
{% endfor -%}
{% endif -%}
{% if pip_proxy | length > 0 -%}
proxy = {{ pip_proxy }}
{% endif -%}
dest: "~{{ item }}/.pip/pip.conf"
become: True
become_user: "{{ item }}"
loop: "{{ pip_applicable_users }}"
- name: Create .pydistutils.cfg
copy:
content: |
[easy_install]
index-url = {{ pip_index_url }}
dest: "~{{ item }}/.pydistutils.cfg"
when: pip_index_url | length > 0
become: True
become_user: "{{ item }}"
loop: "{{ pip_applicable_users }}"