Ansible:用pip安装python子包

时间:2018-06-03 12:52:18

标签: pip ansible

我正在尝试使用Ansible安装气流,所以我有这个命令

- pip
  name: apache-airflow[s3, postgres]
  version: 1.9.0

但是这个错误就失败了:

  

pip2安装 apache-airflow [s3 == 1.9.0 postgres == 1.9.0 celery] == 1.9.0   无效要求:'apache-airflow [s3 == 1.9.0'   Traceback(最近一次调用最后一次):   在from_line中输入文件“/usr/lib/python2.7/site-packages/pip/_internal/req/req_install.py”,第252行   req =要求(要求)   在 init 中输入文件“/usr/lib/python2.7/site-packages/pip/_vendor/packaging/requirements.py”,第97行   requirements_string [e.loc:e.loc + 8]))   InvalidRequirement:无效的需求,解析错误在''[ s3 == 1.9 '“

因此它认为该版本适用于每个子包,但它不适用。它应该尝试安装

apache-airflow[s3, postgres]==1.9.0

在Ansible中安装子包的方法是什么?

1 个答案:

答案 0 :(得分:2)

根据这个github issue,您应该使用以下语法:

  - name: install with pip
    pip:
      name: 
        - 'apache-airflow[s3,postgres]'
      version: 1.9.0

请注意[s3,postgres]中的空格字符已被删除。

更新:当有空格字符时,我会得到与OP问题相同的行为,这就是为什么我建议将其删除(因为github问题也是如此):

错误当有空格字符时,[s3,postgres]

[root@greenhat-28 php_basedir]# cat testtt.yml 
---
- hosts: localhost
  connection: local
  gather_facts: false
  vars:

  tasks:

  - name: install with pip
    pip:
      name: 
        - 'apache-airflow[s3, postgres]'
      version: 1.9.0
[root@greenhat-28 php_basedir]# ansible-playbook testtt.yml 
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [localhost] ****************************************************************************************************************************************************************************************************

TASK [install with pip] *********************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "cmd": "/usr/bin/pip2 install apache-airflow[s3, postgres]==1.9.0", "msg": "\n:stderr: WARNING: Running pip install with root privileges is generally not a good idea. Try `pip2 install --user` instead.\nInvalid requirement: 'apache-airflow[s3,'\nTraceback (most recent call last):\n  File \"/usr/lib/python2.7/site-packages/pip/req/req_install.py\", line 82, in __init__\n    req = Requirement(req)\n  File \"/usr/lib/python2.7/site-packages/pip/_vendor/packaging/requirements.py\", line 96, in __init__\n    requirement_string[e.loc:e.loc + 8]))\nInvalidRequirement: Invalid requirement, parse error at \"'[s3,'\"\n\n"}
        to retry, use: --limit @/php_basedir/testtt.retry

PLAY RECAP **********************************************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1   

[root@greenhat-28 php_basedir]#