Some syntax cleanup.

This commit is contained in:
Andrea Dell'Amico 2022-07-18 19:16:23 +02:00
parent c13b556fc8
commit 93b7887f26
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
1 changed files with 138 additions and 91 deletions

View File

@ -2,35 +2,53 @@
# #
# Note: the library role 'tomcat' is a dependency # Note: the library role 'tomcat' is a dependency
# #
- name: Manage the tomcat main instance
block:
- name: disable the tomcat main instance - name: disable the tomcat main instance
service: name='tomcat{{ tomcat_version }}' state=stopped enabled=no service:
name: 'tomcat{{ tomcat_version }}'
state: stopped
enabled: false
when: not tomcat_service_enabled when: not tomcat_service_enabled
tags: ['tomcat', 'tomcat_instances'] tags: ['tomcat', 'tomcat_instances']
- name: Manage the tomcat user and directory tree
block:
- name: Create a tomcat user for each instance if needed - name: Create a tomcat user for each instance if needed
user: name={{ item.user }} home={{ item.user_home }} createhome=false shell={{ item.user_shell | default('/bin/false') }} user:
with_items: '{{ tomcat_m_instances }}' name: '{{ item.user }}'
home: '{{ item.user_home }}'
createhome: false
shell: "{{ item.user_shell | default('/bin/false') }}"
loop: '{{ tomcat_m_instances }}'
when: when:
- not tomcat_m_use_default_user | bool - not tomcat_m_use_default_user | bool
- item.user != "tomcat{{ tomcat_version }}" - item.user != "tomcat{{ tomcat_version }}"
register: tomcat_first_install register: tomcat_first_install
tags: [ 'tomcat', 'tomcat_instances' ]
- name: Create a tomcat user if needed - name: Create a global tomcat user if needed
user: name={{ tomcat_m_default_user }} home={{ tomcat_m_instances_base_path }} createhome=false shell={{ tomcat_m_default_user_shell }} user:
name: '{{ tomcat_m_default_user }}'
home: '{{ tomcat_m_instances_base_path }}'
createhome: false
shell: '{{ tomcat_m_default_user_shell }}'
when: when:
- tomcat_m_use_default_user | bool - tomcat_m_use_default_user | bool
- tomcat_m_default_user != "tomcat{{ tomcat_version }}" - tomcat_m_default_user != "tomcat{{ tomcat_version }}"
register: tomcat_first_install register: tomcat_first_install
tags: [ 'tomcat', 'tomcat_instances' ]
- name: Create the instances directory trees - name: Create the instances directory trees
file: dest={{ item.0.instance_path }}/{{ item[1] }} owner={{ item.0.user }} group={{ item.0.user }} mode=0755 state=directory file:
dest: '{{ item.0.instance_path }}/{{ item[1] }}'
owner: '{{ item.0.user }}'
group: '{{ item.0.user }}'
mode: 0755
state: directory
with_nested: with_nested:
- '{{ tomcat_m_instances }}' - '{{ tomcat_m_instances }}'
- ['common/classes', 'conf/Catalina/localhost', 'conf/policy.d', 'lib', 'server/classes', 'shared/classes', 'webapps'] - ['common/classes', 'conf/Catalina/localhost', 'conf/policy.d', 'lib', 'server/classes', 'shared/classes', 'webapps']
register: tomcat_first_install register: tomcat_first_install
tags: [ 'tomcat', 'tomcat_instances' ]
- name: Create the tomcat logs base directory - name: Create the tomcat logs base directory
file: file:
@ -40,41 +58,65 @@
tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir'] tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir']
- name: Create the instances log dirs - name: Create the instances log dirs
file: dest={{ tomcat_m_instances_logdir_base }}/{{ item.http_port }} owner={{ item.user }} group={{ item.user }} mode='0750' state=directory file:
with_items: '{{ tomcat_m_instances }}' dest: '{{ tomcat_m_instances_logdir_base }}/{{ item.http_port }}'
owner: '{{ item.user }}'
group: '{{ item.user }}'
mode: '0750'
state: directory
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install register: tomcat_first_install
when: not tomcat_m_expose_log_directory when: not tomcat_m_expose_log_directory
tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir'] tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir']
- name: Create log dirs, readable by the user that runs the http service - name: Create log dirs, readable by the user that runs the http service
file: dest={{ tomcat_m_instances_logdir_base }}/{{ item.http_port }} owner={{ item.user }} group='www-data' mode='0750' state=directory file:
with_items: '{{ tomcat_m_instances }}' dest: '{{ tomcat_m_instances_logdir_base }}/{{ item.http_port }}'
owner: '{{ item.user }}'
group: 'www-data'
mode: '0750'
state: directory
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install register: tomcat_first_install
when: tomcat_m_expose_log_directory when: tomcat_m_expose_log_directory
tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir'] tags: ['tomcat', 'tomcat_instances', 'tomcat_log_dir']
- name: Create the instances work dirs - name: Create the instances work dirs
file: dest={{ tomcat_m_cache_base }}/{{ item.http_port }} owner={{ item.user }} group={{ item.user }} mode=0755 state=directory file:
with_items: '{{ tomcat_m_instances }}' dest: '{{ tomcat_m_cache_base }}/{{ item.http_port }}'
owner: '{{ item.user }}'
group: '{{ item.user }}'
mode: 0755
state: directory
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install register: tomcat_first_install
tags: [ 'tomcat', 'tomcat_instances' ]
- name: Create links to work dir inside the instances directory tree - name: Create links to work dir inside the instances directory tree
file: src={{ tomcat_m_cache_base }}/{{ item.http_port }} dest={{ item.instance_path }}/work state=link file:
with_items: '{{ tomcat_m_instances }}' src: '{{ tomcat_m_cache_base }}/{{ item.http_port }}'
dest: '{{ item.instance_path }}/work'
state: link
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install register: tomcat_first_install
tags: [ 'tomcat', 'tomcat_instances' ]
- name: Create links to log dir inside the instances directory tree - name: Create links to log dir inside the instances directory tree
file: src={{ tomcat_m_instances_logdir_base }}/{{ item.http_port }} dest={{ item.instance_path }}/logs state=link file:
with_items: '{{ tomcat_m_instances }}' src: '{{ tomcat_m_instances_logdir_base }}/{{ item.http_port }}'
dest: '{{ item.instance_path }}/logs'
state: link
loop: '{{ tomcat_m_instances }}'
register: tomcat_first_install register: tomcat_first_install
tags: [ 'tomcat', 'tomcat_instances' ]
- name: Create the catalina tmp directory - name: Create the catalina tmp directory
file: dest={{ item.catalina_tmp_directory }} state=directory owner={{ item.user }} group={{ item.user }} mode=0700 file:
with_items: '{{ tomcat_m_instances }}' dest: '{{ item.catalina_tmp_directory }}'
state: directory
owner: '{{ item.user }}'
group: '{{ item.user }}'
mode: 0700
loop: '{{ tomcat_m_instances }}'
when: item.catalina_tmp_directory is defined when: item.catalina_tmp_directory is defined
tags: ['tomcat', 'tomcat_instances'] tags: ['tomcat', 'tomcat_instances']
- name: Populate the instances conf directory - name: Populate the instances conf directory
@ -202,16 +244,21 @@
tags: ['tomcat', 'tomcat_instances', 'tomcat_jmx'] tags: ['tomcat', 'tomcat_instances', 'tomcat_jmx']
- name: Start all the tomcat instances - name: Start all the tomcat instances
service: name='tomcat-instance-{{ item.http_port }}' state=started sleep=20 service:
with_items: '{{ tomcat_m_instances }}' name: 'tomcat-instance-{{ item.http_port }}'
state: started
sleep: 20
loop: '{{ tomcat_m_instances }}'
when: when:
- tomcat_first_install.changed | bool - tomcat_first_install.changed | bool
- tomcat_m_start_instances | bool - tomcat_m_start_instances | bool
tags: ['tomcat', 'tomcat_instances'] tags: ['tomcat', 'tomcat_instances']
ignore_errors: True ignore_errors: true
- name: Enable all the tomcat instances - name: Enable all the tomcat instances
service: name='tomcat-instance-{{ item.http_port }}' enabled=yes service:
with_items: '{{ tomcat_m_instances }}' name: 'tomcat-instance-{{ item.http_port }}'
enabled: true
loop: '{{ tomcat_m_instances }}'
when: tomcat_m_enable_instances | bool when: tomcat_m_enable_instances | bool
tags: ['tomcat', 'tomcat_instances'] tags: ['tomcat', 'tomcat_instances']