0

I have a tomcat server with 200 instances. I have created a playbook for deploying a new server and it works fine, BUT

I have several plays that manipulate numerous files in each tomcat-instance, and the way it is going now is that the ansible-server connects to the target server for each command. and that is very slow, but it works

what I would like was for some speedup to the process by executing more commands pr connection.

instead of:

..
..
 - name: create dir structure for tomcats
    file:
      dest: "/data/tomcat/tomcat-instance{{ item[1] }}/{{ item[0] }}/"
      state: directory
      owner: root
      group: appuser
      mode: 0770
      recurse: yes
    vars:
      dirs:
        - work
        - webapps
        - temp
        - conf
    loop: "{{ dirs  | product(range(1, ( tomcat_count +1 | int ) ))  | list }}"

                          ## range requieres +1 because last number is not inside the range

  - name: create dir structure - log
    file:
      dest: "/var/log/tomcat-instance{{ item }}"
      state: directory
      owner: root
      group: appuser
      mode: 0770
      recurse: yes
    with_sequence: count={{ tomcat_count }}


  - name: create dir structure-links
    file:
      src: "/opt/tomcat-{{ tomcat_version[0] }}/{{ item [0] }}"
      dest: "/data/tomcat/tomcat-instance{{ item[1] }}/{{ item[0] }}"
      state: link
    vars:
      dirs:
        - bin
        - lib
        - webapps/manager
    loop: "{{ dirs  | product(range(1, ( tomcat_count +1 | int ) ))  | list }}"
                      ## range requieres +1 because last number is not inside the range

  - name: create config structure-links
    file:
      src: "/opt/tomcat-{{ tomcat_version[0] }}/conf/{{ item [0] }}"
      dest: "/data/tomcat/tomcat-instance{{ item[1] }}/conf/{{ item[0] }}"
      state: link
    vars:
      dirs:
        - catalina.properties
        - catalina.policy
        - web.xml
        - tomcat-users.xml
    loop: "{{ dirs  | product(range(1, ( tomcat_count +1 | int ) ))  | list }}"



  - name: create dir structure-links log
    file:
      src: "/var/log/tomcat-instance{{ item }}"
      dest: "/data/tomcat/tomcat-instance{{ item }}/logs"
      state: link
    with_sequence: count={{ tomcat_count }}


- name: create server.xlm port defnitions
  vars:
    ShutDownPort: "{{ (item|int) * 100 + 8005 }}"
    HttpPort: "{{ (item|int) * 100 + 8080 }}"
    AjpPort: "{{ (item|int) * 100 + 8009 }}"
    JvmRoute: "{{ ansible_hostname }}{{ item }}"
    TomcatHome: "/data/tomcat/tomcat-instance{{ item }}"
  template:
    src: tomcat_server_xlm_template
    #dest: /data/tomcat/tomcat-instance{{ item }}/conf/server.xml
    dest: /data/tomcat/tomcat-instance{{ item }}/conf/server-7.xml
  with_sequence:  count={{ tomcat_count }}

..
..

this is just a part of the play and it takes just about forever to run

can I bundle the 'with_sequence' tasks for quicker execution or am I completly off the board with this solution ?

MSchultz
  • 11
  • 4
  • Note that `with_sequence` is deprecated and should be replaced by `loop`. – Michael Hampton Sep 01 '20 at 19:00
  • It's bad - and it's ugly - and it's not good - but what about a template that contains all commands and push that to the server and execute it there. Of course it's not really "ansible" but the roundtrips cannot be avoided because Ansible needs to know idempotent about every step it it works. – TRW Jan 11 '21 at 11:55
  • @TRW just about the same I've ended up with ;) – MSchultz Jan 12 '21 at 12:18

0 Answers0