How to use pip module wiht multiple packages and versions

2,077 views
Skip to first unread message

Tiglath

unread,
Jun 29, 2016, 5:41:20 PM6/29/16
to Ansible Project

I have a long list packages to install in the fashion:

pip install <package>==<version>

I can see that you can do
 
pip: name={{ item }} state=present
with_items:
- <package>
- <package>
...

But how can I specify the version in a loop?

Sorry, new at this...

Many thanks


Kai Stian Olstad

unread,
Jun 30, 2016, 2:02:56 AM6/30/16
to ansible...@googlegroups.com
On 29.06.2016 23:41, Tiglath wrote:
> pip install <package>==<version>
>
> I can see that you can do
>
>
> pip: name={{ item }} state=present
> with_items:
> - <package>
> - <package>
> ...
>
> But how can I specify the version in a loop?

I do this

- pip:
name={{ item.name }}
version={{ item.version | default(omit) }}
with_items:
- name: pack1
version: 1.1
- name: pack2
- name: pack3
- name: pack4
version: 5.0

As you can see, you'll be able to mix packages with or without version
requirement.

--
Kai Stian Olstad

Tiglath

unread,
Jun 30, 2016, 9:48:22 AM6/30/16
to Ansible Project, ansible-pr...@olstad.com

That is great. 

Gratitude!
Reply all
Reply to author
Forward
0 new messages