Skip to content

Commit

Permalink
Merge pull request #131 from idealista/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sorobon authored Nov 20, 2024
2 parents 461722c + 40e7019 commit f26d0b3
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 46 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog).

## Added
- *[#125](https://github.com/idealista/tomcat_role/pull/125) (2024-01-17)- Add ".gitattributes" file for linguist detection.* @ygomezsaiz


## [Unreleased](https://github.com/idealista/tomcat_role/tree/develop)

## [1.12.0](https://github.com/idealista/tomcat_role/tree/1.12.0)
[Full Changelog](https://github.com/idealista/tomcat_role/compare/1.11.0...1.12.0)
### Fixed
- *[#129](https://github.com/idealista/tomcat_role/issues/129) Agent extensions cleanup* @sorobon
### Added
- *[#108](https://github.com/idealista/tomcat_role/issues/108) Apache Tomcat 8.5.51 adds a secret required attribute to the AJP Connector #108* @sm97
- *[#107](https://github.com/idealista/tomcat_role/issues/107) Allow to override configuration files deployed by role* @sm97
- *[#106](https://github.com/idealista/tomcat_role/issues/106) Add extra jar files download* @sm97
- *[#125](https://github.com/idealista/tomcat_role/pull/125) (2024-01-17)- Add ".gitattributes" file for linguist detection.* @ygomezsaiz

## [1.11.0](https://github.com/idealista/tomcat_role/tree/1.11.0)
[Full Changelog](https://github.com/idealista/tomcat_role/compare/1.10.4...1.11.0)
Expand Down
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ ansible-lint = "==4.2.0"

[requires]
python_version = "3.9"
python_full_version = "3.9.18"
3 changes: 1 addition & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ tomcat_service_state: started

# Files & Paths
tomcat_install_path: "/opt/tomcat"
tomcat_lib_path: "{{ tomcat_install_path }}/lib"
tomcat_bin_path: "{{ tomcat_install_path }}/bin"
tomcat_conf_path: "{{ tomcat_install_path }}/conf"
tomcat_webapps_path: "{{ tomcat_install_path }}/webapps"

# Tomcat configuration files to deploy by role
tomcat_conf_templates:
- { src: "tomcat-users.xml.j2", dest: "{{ tomcat_conf_path }}/tomcat-users.xml" }
- { src: "server.xml.j2", dest: "{{ tomcat_conf_path }}/server.xml" }
- { src: "setenv.sh.j2", dest: "{{ tomcat_bin_path }}/setenv.sh" }
- { src: "logging.properties.j2", dest: "{{ tomcat_conf_path }}/logging.properties" }

# Allowing playbooks to provide external config files&templates
tomcat_extra_conf_path: "{{ playbook_dir }}/files/tomcat/conf"
tomcat_extra_conf_template_path: "{{ playbook_dir }}/templates/tomcat/conf"
tomcat_extra_conf_files: "{{ lookup('filetree', '{{ tomcat_extra_conf_path }}/', '{{ tomcat_extra_conf_template_path }}/') | map(attribute='path') | list }}"

## Miscellaneous
tomcat_force_reinstall: false
Expand All @@ -37,6 +46,7 @@ tomcat_http_connector_port: 8080
tomcat_http_connector_connection_timeout: 20000

tomcat_ajp_connector_port: 8009
tomcat_ajp_connector_secret: changeme
tomcat_connector_redirect_port: 8443

## CATALINA_OPTS
Expand Down Expand Up @@ -70,6 +80,9 @@ tomcat_war_to_deploy_from_maven:
# If using Ansible 2.6 or newer, this is settable as well
# verify_checksum: always

tomcat_download_jars: false
tomcat_jar_to_deploy_urls: []

tomcat_download_wars: false
tomcat_war_to_deploy_urls:
- url: https://tomcat.apache.org/tomcat-8.5-doc/appdev/sample/sample.war
Expand Down
17 changes: 6 additions & 11 deletions molecule/default/group_vars/tomcat/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

tomcat_agents_required_libs:
- unzip
- apt-transport-https
Expand All @@ -9,7 +8,7 @@ tomcat_agents_config:
download_url: "http://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip"
version: "8.12.0"
catalina_opts:
- '-javaagent:{{ tomcat_install_path }}/newrelic/newrelic.jar'
- "-javaagent:{{ tomcat_install_path }}/newrelic/newrelic.jar"
configuration_files:
- "newrelic.yml"
extensions:
Expand All @@ -19,26 +18,22 @@ tomcat_agents_config:
- "https://download.newrelic.com/newrelic/java-agent/extensions/c3p0-0.9.jar"
templates:
- "tomcat/agents/newrelic/extensions/extension-example.xml"
params: {
application_name: "application_sample_name",
license_key: "sddsasd"
}
params:
{ application_name: "application_sample_name", license_key: "sddsasd" }
- name: "datadog"
download_url: "https://github.com/DataDog/dd-trace-java/releases/download/v0.73.0/dd-java-agent-0.73.0.jar"
version: "0.73.0"
catalina_opts:
- '-javaagent:{{ tomcat_install_path }}/datadog/dd-java-agent-0.73.0.jar -Ddd.profiling.enabled=true -Ddd.logs.injection=true -Ddd.service=sample -Ddd.env=molecule'
- "-javaagent:{{ tomcat_install_path }}/datadog/dd-java-agent-0.73.0.jar -Ddd.profiling.enabled=true -Ddd.logs.injection=true -Ddd.service=sample -Ddd.env=molecule"
configuration_files: []
- name: "otel"
version: "2.5.0"
download_url: "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.5.0/opentelemetry-javaagent.jar"
catalina_opts:
- '-javaagent:{{ tomcat_install_path }}/otel/opentelemetry-javaagent.jar -Dotel.javaagent.configuration-file={{ tomcat_install_path }}/otel/otel.properties'
- "-javaagent:{{ tomcat_install_path }}/otel/opentelemetry-javaagent.jar -Dotel.javaagent.configuration-file={{ tomcat_install_path }}/otel/otel.properties"
configuration_files:
- "otel.properties"
params: {
service_name: "application_sample_name"
}
params: { service_name: "application_sample_name" }

tomcat_logs_path: /var/log/tomcat

Expand Down
62 changes: 48 additions & 14 deletions tasks/agent.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- name: Tomcat | agent installation | Install required packages
apt:
pkg: "{{ tomcat_agents_required_libs }}"
Expand All @@ -13,7 +12,7 @@
state: directory
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
with_items: '{{ tomcat_agents_config }}'
with_items: "{{ tomcat_agents_config }}"

- name: Tomcat | agent installation | Check if agent is installed
stat:
Expand All @@ -38,16 +37,16 @@
url: "{{ item.download_url }}"
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
mode: '666'
mode: "666"
register: agent_downloaded
loop: "{{ tomcat_agents_config|flatten(levels=1) }}"
loop_control:
index_var: index
when: >
item.download_url | basename | splitext | last in tomcat_supported_agents_extensions and
(tomcat_agents_force_reinstall or not
agent_file_exists.results[index].stat.exists or
item.version != agent_version_checked.results[index].stdout)
item.download_url | basename | splitext | last in tomcat_supported_agents_extensions and
(tomcat_agents_force_reinstall or not
agent_file_exists.results[index].stat.exists or
item.version != agent_version_checked.results[index].stdout)
- name: Tomcat | agent installation | Unarchive package
unarchive:
Expand All @@ -58,7 +57,7 @@
group: "{{ tomcat_group }}"
mode: 0755
when: item.changed and item.url | basename | splitext | last in tomcat_supported_agents_extensions
with_items: '{{ agent_downloaded.results }}'
with_items: "{{ agent_downloaded.results }}"
tags:
- skip_ansible_lint

Expand All @@ -68,7 +67,7 @@
url: "{{ item.download_url }}"
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
loop: '{{ tomcat_agents_config | flatten(levels=1) }}'
loop: "{{ tomcat_agents_config | flatten(levels=1) }}"
register: agent_jar_downloaded
when: item.download_url | basename | splitext | last not in tomcat_supported_agents_extensions

Expand All @@ -79,7 +78,7 @@
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
mode: 0644
with_items: '{{ tomcat_agents_config }}'
with_items: "{{ tomcat_agents_config }}"

- name: Tomcat | agent installation | Check configuration files
set_fact:
Expand All @@ -97,7 +96,7 @@
when: tomcat_agent_configuration is defined
notify: restart tomcat
with_items:
- '{{ tomcat_agent_configuration }}'
- "{{ tomcat_agent_configuration }}"

- name: Tomcat | agent installation | Check catalina options
set_fact:
Expand All @@ -117,12 +116,11 @@
- { src: "setagentenv.sh.j2", dest: "{{ tomcat_bin_path }}/setagentenv.sh" }
notify: restart tomcat


- name: Tomcat | agent installation | Setting extensions var
set_fact:
tomcat_agent_configuration_extensions_config: "{{ tomcat_agent_configuration_extensions_config|default([]) + [ {'name': item.name, 'files': item.extensions.files, 'path': item.extensions.path}] }}"
tomcat_agent_configuration_extensions_config: "{{ tomcat_agent_configuration_extensions_config|default([]) + [ {'name': item.name, 'files': item.extensions.files|default([]), 'path': item.extensions.path}] }}"
loop: "{{ tomcat_agents_config }}"
when: item.extensions.files is defined
when: item.extensions is defined

- name: Tomcat | agent installation | Ensure extensions path
file:
Expand All @@ -132,6 +130,40 @@
group: "{{ tomcat_group }}"
loop: "{{ tomcat_agent_configuration_extensions_config }}"
when: tomcat_agent_configuration_extensions_config is defined
changed_when: false

- name: Tomcat | agent installation | List existent extensions
find:
paths: "{{ item.extensions.path }}"
patterns: "*.jar"
loop: "{{ tomcat_agents_config }}"
when: item.extensions is defined
register: tomcat_agents_existent_extensions

- name: Tomcat | agent installation | Setting extensions var for removing
set_fact:
tomcat_agents_existent_extensions_list: "{{ tomcat_agents_existent_extensions_list|default([]) + item.files | map(attribute='path') | list }}"
loop: "{{ tomcat_agents_existent_extensions.results }}"
when: item.files is defined

- name: Tomcat | agent installation | Extract files paths from configuration
set_fact:
config_files: "{{ config_files|default([]) + [item.0.path ~ '/' ~ item.1 | basename] }}"
with_subelements:
- "{{ tomcat_agent_configuration_extensions_config }}"
- files
when: tomcat_agent_configuration_extensions_config is defined

- name: Tomcat | agent installation | Calculate difference
set_fact:
files_to_remove: "{{ tomcat_agents_existent_extensions_list | difference(config_files) }}"

- name: Tomcat | agent installation | Remove old extensions
file:
path: "{{ item }}"
state: absent
loop: "{{ files_to_remove }}"
when: files_to_remove is defined

- name: Tomcat | agent installation | Download extensions
get_url:
Expand All @@ -143,6 +175,7 @@
- "{{ tomcat_agent_configuration_extensions_config }}"
- files
when: tomcat_agent_configuration_extensions_config is defined
changed_when: false

- name: Tomcat | agent installation | Setting extensions var for templates
set_fact:
Expand All @@ -169,3 +202,4 @@
- "{{ tomcat_agents_templates_extensions_config }}"
- templates
when: tomcat_agents_templates_extensions_config is defined
changed_when: false
10 changes: 3 additions & 7 deletions tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@

- name: Tomcat | Copy tomcat config
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
src: "{{ tomcat_conf_templates | selectattr('src', 'equalto', item) | map(attribute='src') | first }}"
dest: "{{ tomcat_conf_templates | selectattr('src', 'equalto', item) | map(attribute='dest') | first }}"
mode: 0640
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
with_items:
- { src: "tomcat-users.xml.j2", dest: "{{ tomcat_conf_path }}/tomcat-users.xml" }
- { src: "server.xml.j2", dest: "{{ tomcat_conf_path }}/server.xml" }
- { src: "setenv.sh.j2", dest: "{{ tomcat_bin_path }}/setenv.sh" }
- { src: "logging.properties.j2", dest: "{{ tomcat_conf_path }}/logging.properties" }
with_items: "{{ tomcat_conf_templates | map(attribute='src') | difference(tomcat_extra_conf_files) | list }}"
notify: restart tomcat

- name: Tomcat | Ensure extra tomcat config file and template paths exists
Expand Down
12 changes: 12 additions & 0 deletions tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,15 @@
group: "{{ tomcat_group }}"
with_items: "{{ tomcat_war_to_deploy_path }}"
when: tomcat_local_wars

- name: Tomcat | Download extra jars
get_url:
url: "{{ item.url }}"
dest: "{{ tomcat_lib_path }}/{{ item.name }}"
mode: 0755
validate_certs: false
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
with_items: "{{ tomcat_jar_to_deploy_urls }}"
notify: restart tomcat
when: tomcat_download_jars
11 changes: 5 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
---

- name: Tomcat | Install
import_tasks: install.yml
tags:
- install
- tomcat_install

- name: Tomcat | Service
import_tasks: service.yml
tags:
- service
- tomcat_service

- name: Tomcat | Config
import_tasks: config.yml
tags:
- config
- tomcat_config

- name: Tomcat | Agent config
import_tasks: agent.yml
tags:
- agent_config
- tomcat_agent_config
when: tomcat_agents_config is defined

- name: Tomcat | Deploy
import_tasks: deploy.yml
tags:
- deploy
- tomcat_deploy
2 changes: 1 addition & 1 deletion templates/server.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="{{ tomcat_ajp_connector_port }}" protocol="AJP/1.3" redirectPort="{{ tomcat_connector_redirect_port }}"/>
<Connector port="{{ tomcat_ajp_connector_port }}" secret="{{ tomcat_ajp_connector_secret }}" protocol="AJP/1.3" redirectPort="{{ tomcat_connector_redirect_port }}"/>


<!-- An Engine represents the entry point (within Catalina) that processes
Expand Down

0 comments on commit f26d0b3

Please sign in to comment.