<p>You can loop over file content:</p>

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

CC BY-SA 4.0
2018-11-28T12:27:12.630Z
2018-11-28T12:27:12.630Z
storm
<p>You can loop with dictionaries using <code>loop</code>. It doesn't look like the <code>easy_install</code> module handles versions with a module attribute, so you might have t pass the version on the <code>name</code> attribute.</p>

<pre><code>- name: install things with easy_install
  easy_install:
    name: "{{ item.name }}=={{item.version}}"
    state: present
  loop:
    - { name: 'pip', version: '18.1' }
</code></pre>

CC BY-SA 4.0
2018-11-28T12:20:16.980Z
2018-11-28T12:20:16.980Z
Bruce Becker
<p>I want to run <a href="https://docs.ansible.com/ansible/2.4/easy_install_module.html" rel="nofollow noreferrer">easy_install</a> task in order to install many modules in virtual environment.</p>

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

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

<pre><code>- name: Install things 
  easy_install:
   name: pip
   state: latest
</code></pre>

<p>I want certain versions obviously...</p>

<p>I can not work with Pip task, only easy_install.
Thanks</p>

CC BY-SA 4.0
2018-11-28T12:15:05.540Z
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.
Bruce Becker
CC BY-SA 4.0
2018-11-28T12:27:04.647Z
version: ansible 2.5.1
amichib
<ansible>
ansible task -easy_install with requirements.txt file
amichib
# ansible task -easy_install with requirements.txt file

(Asked by: username_0 on 2018-11-28)

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

**Tags:** ansible

> **Comments:**
> **username_1**: 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.  
> **username_0**: version: ansible 2.5.1  

---

## 2 answers

### Answer by username_2 on 2018-11-28. Score: 1 | Accepted answer

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"


---

### Answer by username_1 on 2018-11-28. Score: 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' }


---

