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
You'd have to manually split that and trim the results so you can use
it in a loop.
Where does that "user1, user2, user3" string come from?
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 ?
That list of users only has the usernames.
If you loop over them, and that is all the information you have, they
will all have the same password.
Are you sure that is what you want?
Yes, All I want to create is the user from the list (vars). This will be hard coded value from the vars and the password will be the same for all the users.
If you supply the list as:
vars:
schemaname:
- user1
- user2
- user3
then it's as easy as:
loop: "{{ schemaname }}"
If you get that comma delimited string from somewhere else (which I
asked but got no response to), then you'd have to manually split and
trim:
loop: "{{ schemaname.split(',') | map('trim') | list }}"