[英]ansible pip: recursively install wheels in a virtualenv
要從文件夾/tmp/prod_wheel/
安裝所有輪子,我這樣做:
$ 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
它運作良好。
現在我的情況是,輪子位於我不知道名稱的文件夾中,例如/tmp/data/*/*.whl
fileglob
不 glob 文件夾(僅文件)。
我使用 find 來捕捉輪子,但是在我的 virtualenv 中安裝它們的更緊湊的方法是什么?
$ echo playbook_catch_wheels.yml
---
- hosts: localhost
tasks:
- name: Find to catch recursively all wheels
find:
paths: /vagrant/vagrant/*/dist/
patterns: '*.whl'
您可以簡單地使用map
過濾器從find
結果中提取路徑列表,並將其傳遞給pip
,就像您之前對fileglob
查找所做的那樣。
理所當然地認為您的實際find
任務會返回您期望的結果(自從您提到它以來我仍然添加了recurse
)以下兩個任務應該滿足您的要求:
---
- 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
請注意, find
解決方案比fileglob
查找更便攜,因為如果需要,它可以在遠程主機上工作。 查找始終在本地運行,而查找在目標主機上運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.