Ewurama's picture
I am trying to create multiple directories with different names e.g tomacat-1, tomcat-2 etc..
But i want to do this in the form of a loop. Kindly help me with the yaml syntax.
this is what i tried
- name: Creating multiple tomcat instance
  file: dest=/var/lib/tomcat-instance{1..3}  state=directory
But instead of creating three directories, it creates only one with name "tomcat-instance{1..3}"
Also i would like each of these folders to have a unique port id and shutdown port  e.g     -p  8000  -c 8006
Jeremy Davis's picture

Our community member John Carver made the Ansible appliance. I'll give him a shout out and see if he can help.

In the meantime eprhaps google might help? Or ansible upstream may have forums and/or a mailing list where someone from there community could help you out.

John Carver's picture

@Ewurama, I don't think {1..3} is a valid syntax in yaml.  Perhaps you were thinking of Ruby or similar language.  Instead you can use 'with_sequence' like this

- hosts: localhost
  become: yes
  become_user: root


    - name: Creating multiple tomcat instance
      file: dest=/var/lib/tomcat-instance{{ item }}  state=directory
      with_sequence: start=1 end=3

After running ansible-playbook tomcat.yml (above)

$ ls /var/lib/tomcat-instance*



I don't know enough about Tomcat to help with the remainer of your question, but perhaps you can find some clues by reading some of the Ansible Tomcat modules developed by others.  E.g. see https://github.com/silpion/ansible-tomcat

Information is free, knowledge is acquired, but wisdom is earned.

John Carver's picture

@Ewurama, You could also try experimenting the some of the Tomcat roles defined on Ansible Galaxy

cd ~/roles
ansible-galaxy install mohammad.tomcat-8



Information is free, knowledge is acquired, but wisdom is earned.

Add new comment