# Simple Loops in Ansible

**URL:** <https://forum.ansible.com/t/simple-loops-in-ansible/32065>\
**Category:** Ansible Developer\
**Created:** [January 27, 2020, 2:56pm UTC](https://forum.ansible.com/t/simple-loops-in-ansible/32065 "2020-01-27T14:56:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Solomon](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anand\_Solomon](https://forum.ansible.com/u/Anand_Solomon)\
**Post date:** [January 27, 2020, 2:56pm UTC](https://forum.ansible.com/t/simple-loops-in-ansible/32065/1 "2020-01-27T14:56:31Z")

</div>

Hi,  
I want to create users in the database using Ansible. I need ansible to run the task (creating user) for all the users mentioned in the vars: schemaname. How do I do that in loop ?

var:  
schemaname: user1, user2, user3

tasks:

- name: This playbook will create the user.  
oracle\_user:  
oracle\_home: /home/ansible/instantclient\_12\_2  
user: “{{user}}”  
password: “{{password}}”  
service\_name: “{{sname}}”  
port: “{{prt}}”  
hostname: “{{hostname}}”  
schema: “{{schemaname}}”  
schema\_password:  
default\_tablespace: USERS  
state: present  
update\_password: on\_create  
grants: “DBA”  
environment: “{{oracle\_env}}”  
register: user\_create  
delegate\_to: localhost

---

<div class="post-metadata">

**Author:** ![Rajat\_Taneja](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@Rajat\_Taneja](https://forum.ansible.com/u/Rajat_Taneja)\
**Post date:** [January 27, 2020, 6:04pm UTC](https://forum.ansible.com/t/simple-loops-in-ansible/32065/2 "2020-01-27T18:04:32Z")

</div>

You can use with\_items module. You can read more about it here:  
[https://docs.ansible.com/ansible/latest/playbooks\_loops.html](https://docs.ansible.com/ansible/latest/playbooks_loops.html)

Thanks,  
Rajat
