0

I have a file data like below:

[prod]
product=Admin;Financial;Hrm

When I try to access file data I am getting complete line, like Admin;Financial;Hrm but for the first loop I have to take only Admin, and for the second loop I should get Financial and for the third loop I should get the hrm.

And I am accessing the file data and assigning it to a variable like:

- set_fact: product={{ lookup('ini', 'product type=prod file=vars.properties') }}"

And my below playbooks should loop accroding to the product

The playbooks are like below

- name: This task is to loop ansible playbook according to inputs with delimiters
  debug: msg="{{product}}"

- include: sudo ansible-playbook create_new_env_adm.yml --extra-vars "Release=3.11.1"
  when: 
    - '"appfolder" == "ADM"'
    - '"product"=="Admin"'`

- include: sudo ansible-playbook create_new_env_fin.yml --extra-vars "Release=3.11.2"
  when:
    - '"appfolder" == "fin"'
    - '"product"=="Financial"'`

- include: sudo ansible-playbook create_new_env_hrm.yml --extra-vars "Release=3.11.3"
  when: 
    - '"appfolder" == "hrm"'
    - '"product"=="Hrm"'
techraf
  • 64,883
  • 27
  • 193
  • 198
monu
  • 23
  • 1
  • 8
  • It's not directly related to the question, but I don't think the lookup plugin-call with `type=prod` works with the example file you posted. Does it? ・ Also not related, but the whole idea seems a somewhat strange implementation. ・ Finally you mention some loops in the title and the body, but no loop is in the code, not even a requirement for a loop. – techraf Dec 18 '17 at 01:32

1 Answers1

1

Example syntax (using the split operator to convert the string to a list and a containment test to check if an element is on the list):

when: 
  - "'Admin' in product.split(';')"

You might want to move .split to the variable definition for better code readability.

techraf
  • 64,883
  • 27
  • 193
  • 198
  • Thanks@techraf, `when: "'Admin' in product.split(';')"` worked for me. – monu Dec 18 '17 at 03:37
  • Please have a look at the Help Center: [do not add a comment on your question or on an answer to say "Thank you".](http://stackoverflow.com/help/someone-answers) – techraf Dec 18 '17 at 05:08