To install all wheels from a folder /tmp/prod_wheel/
I do this:
$ cat playbook_install.yml
---
- hosts: localhost
tasks:
- name: Install all wheels
pip:
name: "{{ query('fileglob', '/tmp/prod_wheel/*.whl') }}"
virtualenv: "~/venv"
virtualenv_command: /usr/bin/python3 -m venv ~/venv
It's working well.
Now I have a situation where wheels are in folders I don't known the names, eg /tmp/data/*/*.whl
the fileglob
does not glob folders (only files).
I use find to catch wheels, but what is the more compact way to install them in my virtualenv?
$ echo playbook_catch_wheels.yml
---
- hosts: localhost
tasks:
- name: Find to catch recursively all wheels
find:
paths: /vagrant/vagrant/*/dist/
patterns: '*.whl'
You can simply extract the list of paths from your find
result with the map
filter and pass it to pip
, as you previously did with your fileglob
lookup.
Taking for granted your actual find
task returns what you expect (I still added recurse
since you mentioned it) the following two tasks should meet your requirement:
---
- hosts: localhost
tasks:
- name: Find to catch recursively all wheels
find:
paths: /vagrant/vagrant/*/dist/
patterns: '*.whl'
recurse: true
register: wheel_search
- name: Install all found wheels
pip:
name: "{{ wheel_search.files | map(attribute='path') | list }}"
virtualenv: "~/venv"
virtualenv_command: /usr/bin/python3 -m venv ~/venv
Note that the find
solution is much more portable than the fileglob
lookup, as it will work on a remote host if needed. Lookups are always running locally whereas find runs on the target host.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.