Skip to content

Instantly share code, notes, and snippets.

@Aethylred
Last active July 19, 2018 21:21
Show Gist options
  • Save Aethylred/4e9d4dca6ed44b477c9e4157afb113cc to your computer and use it in GitHub Desktop.
Save Aethylred/4e9d4dca6ed44b477c9e4157afb113cc to your computer and use it in GitHub Desktop.
Iterate over a pip requirements.txt file
- name: Debug pip with large requirements file
hosts: 127.0.0.1
connection: local
become: yes
tasks:
- name: Get the requirements file
slurp:
src: /opt/awx/requirements/requirements.txt
register: reqfile
- name: Install Python module requirements
pip:
name: "{{ item | regex_search('^(?P<mod>\\S*)==(?P<ver>\\S*)','\\g<mod>') | first }}"
version: "{{ item | regex_search('^(?P<mod>\\S*)==(?P<ver>\\S*)','\\g<ver>') | first }}"
with_items: "{{ (reqfile.content|b64decode).splitlines()|map('regex_replace', '\\s*#.*$', '')|list }}"
when:
- item is defined
- item != ''
@Aethylred
Copy link
Author

So run this as root with:

ansible-playbook pip-iter.yaml

@gundalow
Copy link

https://docs.ansible.com/ansible/latest/modules/pip_module.html

Would this work?

- name: Install Python module requirements
  pip:
    requirements: /opt/awx/requirements/requirements.txt
    executable: pip

@Aethylred
Copy link
Author

@gundalow Sorry, no because of ansible/ansible#42546

@Aethylred
Copy link
Author

Will be fixed after pip 10.0.2 pypa/pip#5366 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment