# What are the different between 2 ways for loop as below

**URL:** <https://forum.ansible.com/t/what-are-the-different-between-2-ways-for-loop-as-below/2504>\
**Category:** Get Help\
**Created:** [November 22, 2023, 2:04am UTC](https://forum.ansible.com/t/what-are-the-different-between-2-ways-for-loop-as-below/2504 "2023-11-22T02:04:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanhnguyen](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@lanhnguyen](https://forum.ansible.com/u/lanhnguyen)\
**Post date:** [November 22, 2023, 2:04am UTC](https://forum.ansible.com/t/what-are-the-different-between-2-ways-for-loop-as-below/2504/1 "2023-11-22T02:04:34Z")

</div>

Could you explain what are the different between 2 ways wrote loop as below?  
Thank you so much.

```auto
- name: Install a list of packages
  ansible.builtin.yum:
    name:
      - nginx
      - postgresql
      - postgresql-server
    state: present

```

```auto
- name: Install a list of packages
  ansible.builtin.yum:
    name="{{ item }}" 
    state: present
    loop:
        - nginx
        - postgresql
        - postgresql-server

```

---

<div class="post-metadata">

**Author:** ![sirjaren](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@sirjaren](https://forum.ansible.com/u/sirjaren)\
**Post date:** [November 22, 2023, 2:46am UTC](https://forum.ansible.com/t/what-are-the-different-between-2-ways-for-loop-as-below/2504/2 "2023-11-22T02:46:14Z")

</div>

The former executes `yum` once and will install the 3 items as arguments to the `yum` binary, resulting in 1 execution of `yum`.

The latter executes `yum {{ item }}` and will install the 3 items by sending a single package to `yum`, 3 times, resulting in 3 executions of `yum`.

---

<div class="post-metadata">

**Author:** ![kurokobo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kurokobo/32/182_2.png) [@kurokobo](https://forum.ansible.com/u/kurokobo)\
**Post date:** [November 22, 2023, 6:49am UTC](https://forum.ansible.com/t/what-are-the-different-between-2-ways-for-loop-as-below/2504/3 "2023-11-22T06:49:21Z")

</div>

```bash
yum install -y nginx postgresql postgresql-server

```

vs.

```bash
yum install -y nginx
yum install -y postgresql 
yum install -y postgresql-server

```

---

<div class="post-metadata">

**Author:** ![mariolenz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mariolenz/32/108_2.png) [@mariolenz](https://forum.ansible.com/u/mariolenz)\
**Post date:** [November 22, 2023, 3:50pm UTC](https://forum.ansible.com/t/what-are-the-different-between-2-ways-for-loop-as-below/2504/4 "2023-11-22T15:50:10Z")

</div>

I want to make something more clear: What you’re showing are _not_ 2 different ways to write a loop.

See the answers from @sirjaren and @kurokobo why the first task isn’t a loop.
