anans pip:在virtualenv中递归安装车轮

问题描述 投票:0回答:1

要从文件夹/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不会显示文件夹(仅文件)。

我使用find来抓住轮子,但是在我的virtualenv中安装轮子的更紧凑的方法是什么?

$ echo playbook_catch_wheels.yml
---
- hosts: localhost
  tasks:

    - name: Find to catch recursively all wheels
      find:
        paths: /vagrant/vagrant/*/dist/
        patterns: '*.whl'
python ansible python-wheel
1个回答
0
投票

您可以像以前使用find查找一样,简单地使用map filtermap结果中提取路径列表,并将其传递给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查找更具可移植性,因为如果需要,它可以在远程主机上工作。查找始终在本地运行,而查找在目标主机上运行。

© www.soinside.com 2019 - 2024. All rights reserved.