diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 38ee35c..056388e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,7 +20,7 @@ repos: pass_filenames: false - repo: https://github.com/robertdebock/pre-commit - rev: v1.1.1 + rev: v1.1.2 hooks: - id: ansible_role_find_unused_variable - id: ansible_role_find_empty_files diff --git a/README.md b/README.md index 24fd4fa..05810a8 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,8 @@ tomcat_ssl_connector_port: 8443 tomcat_shutdown_port: 8005 tomcat_ajp_port: 8009 tomcat_jre_home: /usr +tomcat_service_state: started +tomcat_service_enabled: yes # You can bind Tomcat to a specified address globally using this variable, or # in the `tomcat_instances`. The `tomcat_instances.address` is more specific # so it takes priority over `tomcat_address`. @@ -170,6 +172,8 @@ tomcat_instances: access_log_prefix: "{{ tomcat_access_log_prefix }}" access_log_suffix: "{{ tomcat_access_log_suffix }}" access_log_pattern: "{{ tomcat_access_log_pattern }}" + service_state: "{{ tomcat_service_state }}" + service_enabled: "{{ tomcat_service_enabled }}" # The explicit version to use when referring to the short name. tomcat_version7: 7.0.107 @@ -292,6 +296,7 @@ Apache-2.0 I'd like to thank everybody that made contributions to this repository. It motivates me, improves the code and is just fun to collaborate. - [brunoleon](https://github.com/brunoleon) +- [gaima8](https://github.com/gaima8) - [javid90khan](https://github.com/javid90khan) - [patsevanton](https://github.com/patsevanton) - [till](https://github.com/till) diff --git a/defaults/main.yml b/defaults/main.yml index 14b6a55..b74b4b6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,6 +14,8 @@ tomcat_ssl_connector_port: 8443 tomcat_shutdown_port: 8005 tomcat_ajp_port: 8009 tomcat_jre_home: /usr +tomcat_service_state: started +tomcat_service_enabled: yes # You can bind Tomcat to a specified address globally using this variable, or # in the `tomcat_instances`. The `tomcat_instances.address` is more specific # so it takes priority over `tomcat_address`. @@ -54,8 +56,8 @@ tomcat_instances: access_log_prefix: "{{ tomcat_access_log_prefix }}" access_log_suffix: "{{ tomcat_access_log_suffix }}" access_log_pattern: "{{ tomcat_access_log_pattern }}" - service_state: started - service_enabled: yes + service_state: "{{ tomcat_service_state }}" + service_enabled: "{{ tomcat_service_enabled }}" # The explicit version to use when referring to the short name. tomcat_version7: 7.0.107 diff --git a/tasks/assert.yml b/tasks/assert.yml index 36838e1..d07fff2 100644 --- a/tasks/assert.yml +++ b/tasks/assert.yml @@ -132,6 +132,20 @@ - tomcat_jre_home is string quiet: yes +- name: test if tomcat_service_state is set correctly + assert: + that: + - tomcat_service_state is defined + - tomcat_service_state in [ "reloaded", "restarted", "started", "stopped" ] + quiet: yes + +- name: test if tomcat_service_enabled is set correctly + assert: + that: + - tomcat_service_enabled is defined + - tomcat_service_enabled is boolean + quiet: yes + - name: test if tomcat_instances is set correctly assert: that: @@ -341,3 +355,25 @@ label: "{{ item.name }}" when: - item.config_files is defined + +- name: test if item.service_state in tomcat_instances is set correctly + assert: + that: + - item service_state in [ "reloaded", "restarted", "started", "stopped" ] + quiet: yes + loop: "{{ tomcat_instances }}" + loop_control: + label: "{{ item.name }}" + when: + - item.service_state is defined + +- name: test if item.service_enabled in tomcat_instances is set correctly + assert: + that: + - item service_enabled is boolean + quiet: yes + loop: "{{ tomcat_instances }}" + loop_control: + label: "{{ item.name }}" + when: + - item.service_enabled is defined diff --git a/tasks/instance.yml b/tasks/instance.yml index f50e965..7a4b899 100644 --- a/tasks/instance.yml +++ b/tasks/instance.yml @@ -87,11 +87,11 @@ user_name: "{{ instance.user | default(tomcat_user) }}" group_name: "{{ instance.group | default(tomcat_group) }}" -- name: set tomcat instance service to {{ instance.service_state | default('started') }} and {{ instance.service_enabled | default('yes') }} +- name: manage tomcat service service: name: "{{ instance.name }}" - state: "{{ instance.service_state | default('started') }}" - enabled: "{{ instance.service_enabled | default('yes') }}" + state: "{{ instance.service_state | default(tomcat_service_state) }}" + enabled: "{{ instance.service_enabled | default(tomcat_service_enabled) }}" - name: loop over wars include: war.yml