Dotan
Dotan

Reputation: 7622

Ansible: install python subpackages with pip

I'm trying to install airflow with Ansible, so I have this command

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

But this fails with this error:

pip2 install apache-airflow[s3==1.9.0 postgres==1.9.0 celery]==1.9.0 Invalid requirement: 'apache-airflow[s3==1.9.0' Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/pip/_internal/req/req_install.py", line 252, in from_line req = Requirement(req) File "/usr/lib/python2.7/site-packages/pip/_vendor/packaging/requirements.py", line 97, in init requirement_string[e.loc:e.loc + 8])) InvalidRequirement: Invalid requirement, parse error at "'[s3==1.9'"

So it thinks the version applies to each subpackage, which it doesn't. It should try to install

apache-airflow[s3, postgres]==1.9.0

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

Upvotes: 1

Views: 984

Answers (1)

ilias-sp
ilias-sp

Reputation: 6685

according to this github issue, you should use this syntax:

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

please pay attention that the space character in the [s3,postgres] was removed.

UPDATE: when there is a space character, i get the same behavior like OP's question, this is why i suggest to remove it (as github issue has it as well):

error 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]# 

Upvotes: 2

Related Questions