首页 文章

Ansible:用pip安装python子包

提问于
浏览
1

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

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

但这失败了这个错误:

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

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

apache-airflow[s3, postgres]==1.9.0

What's to correct way to install subpackages in Ansible?

1 回答

  • 2

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

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

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

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

    错误 when there is space character, [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]#
    

相关问题