# Postgresql\_user - loop TASK through more then one list

**URL:** <https://forum.ansible.com/t/postgresql-user-loop-task-through-more-then-one-list/44677>\
**Category:** Get Help\
**Created:** [October 14, 2025, 12:47pm UTC](https://forum.ansible.com/t/postgresql-user-loop-task-through-more-then-one-list/44677 "2025-10-14T12:47:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2025, 12:47pm UTC](https://forum.ansible.com/t/postgresql-user-loop-task-through-more-then-one-list/44677/1 "2025-10-14T12:47:03Z")

</div>

I have a `TASK` to create some postgres user with password

```auto
    - name: create users, set hashed passwords
      community.postgresql.postgresql_user:
        name: "{{ item.name }}"
        password: "{{ item.pw }}"
        encrypted: true
        comment: "{{ item.comment }}"
        role_attr_flags: "{{ item.attr }}"
        login_unix_socket: '/tmp'
      become: true
      become_user: postgres
      loop: "{{ pg_roles }}"

```

`{{ pg_roles }}` comes from `host_vars` file  
now, there are other roles needed that are not specific to a singular host, but are equal for all hosts in the current group.  
so there is `adm_roles` variable defined in `group_vars` file.

Now, I am wondering whether I can loop though both lists (`pg_roles` & `adm_roles`) inside the same TASK or whether there must be a second identical TASK for each list?

I tried:

```auto
...
  login_unix_socket: '/tmp'
become: true
become_user: postgres
loop:
  - "{{ pg_roles }}"
  - "{{ adm_roles }}"

```

but that didn’t work (_list item has no attribute ‘name’_, I think)

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [October 14, 2025, 1:51pm UTC](https://forum.ansible.com/t/postgresql-user-loop-task-through-more-then-one-list/44677/2 "2025-10-14T13:51:40Z")

</div>

Could you post an example of the `adm_roles` and `pg_roles` dictionaries?

---

<div class="post-metadata">

**Author:** ![bvitnik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bvitnik/32/4132_2.png) [@bvitnik](https://forum.ansible.com/u/bvitnik)\
**Post date:** [October 15, 2025, 2:30pm UTC](https://forum.ansible.com/t/postgresql-user-loop-task-through-more-then-one-list/44677/3 "2025-10-15T14:30:50Z")

</div>

@dulhaver Hi. I presume `pg_roles` and `adm_roles` are lists of the same format. In that case you can just concatenate them (add one to another) to form a bigger temporary list with all items from both `pg_roles` and `adm_roles`. It’s easy like this:

```auto
...
loop: "{{ pg_roles + adm_roles }}"

```
