Hello to all Ansible guru :)

I write a playbook to deploy a newest Jboss infrastructure.
I want to use a loop to iterate over a list of items to deploy all the 
datasource I need, all the datasources change based on the environnement 
they're deployed

Here the part of my role to add the datasource:
 
- name: Add datasources
   command: {{ jboss_home }}/bin/jboss-cli.sh -c controller={{ jboss_master 
}}:{{ jboss_master_port }} --user={{ admin_user }} --password={{ 
admin_password }} --command="data-source add --jndi-name={{ item.jndi_name 
}} --name={{ item.ds_name}} --connection-url={{ item.conn_url }} 
--driver-name={{ item.driver_name }} --user-name={{ item.dsusername }} 
--password={{ item.dspassword }} --profile={{ item.ds_profile }}"           
                                        
   with_items:
     - { some vars }
     - { another vars }
     - ...


When I launch the playbook I use a different inventory file based on the 
environnement, like:
ansible-playbook -i testing install-all.yml
or 
ansible-playbook -i production install-all.yml

What's the best pratices to add datasources based on the environnement type 
?
I think about something like:
 command: some_command_with_vars
 with_items:
   - { some_item } 
 when: {{ env }}


But I have to write three blocks with all item for my three environnement 
(the two other will be skipped everytime I run the playbook).

Is there's a way to load dynamically a file containing a dict with all item 
I need based on the environnement ? 
In that way I have to write three file containing the vairables I need 
inthe vars folder (test.yml, val.yml and prod.yml) and load them 
dynamically based on the environnement variable I can set in the inventory 
file. Something like:

command: some_command_with_vars
with_items_in:
  - {{ env }}.yml

Am I and the right way ? What I missed here and how do you handle that ?

Thanks :)



-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/02d17a67-27a1-41e7-b74b-4c6871bb12e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to