I want to run easy_install task in order to install many modules in virtual environment.

Is there an option to install all modules in requirements.txt file? as I understand it accept only one module at a time.

Another option is to do it with with_items but how can I make Ansible iterate over both the name and the version of each module

- name: Install things 
   name: pip
   state: latest

I want certain versions obviously...

I can not work with Pip task, only easy_install. Thanks

  • Can you provide the ansible version? It seems like you're using a slightly older version, referring to with_items - this is replaced by loop in recent versions. Nov 28, 2018 at 12:15
  • version: ansible 2.5.1
    – amichib
    Nov 28, 2018 at 12:27

2 Answers 2


You can loop over file content:

- name: Installs Python libraries from requirements.txt
    name: {{ item }}
    state: present
  with_lines: cat "/my_app/requirements.txt"

You can loop with dictionaries using loop. It doesn't look like the easy_install module handles versions with a module attribute, so you might have t pass the version on the name attribute.

- name: install things with easy_install
    name: "{{ item.name }}=={{item.version}}"
    state: present
    - { name: 'pip', version: '18.1' }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.