2

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 
  easy_install:
   name: pip
   state: latest

I want certain versions obviously...

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

2
  • 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

1

You can loop over file content:

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

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
  easy_install:
    name: "{{ item.name }}=={{item.version}}"
    state: present
  loop:
    - { name: 'pip', version: '18.1' }

Your Answer

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

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