From bf45fee20fe54248116dac16f01f574d57dd7dec Mon Sep 17 00:00:00 2001 From: Santiago Orobon Date: Wed, 14 Feb 2018 14:27:17 +0100 Subject: [PATCH 1/3] [#43] Allow to change log files directory --- .yamllint | 4 + CHANGELOG.md | 2 + defaults/main.yml | 17 ++++ molecule/agent/molecule.yml | 3 +- molecule/agent/tests/dumpall.j2 | 1 + molecule/agent/tests/test_agent.yml | 50 +++++++++++ molecule/agent/tests/test_tomcat.yml.j2 | 52 ----------- molecule/agent/verifier.yml | 24 +++-- molecule/change-log-path/Dockerfile.j2 | 9 ++ molecule/change-log-path/INSTALL.rst | 16 ++++ molecule/change-log-path/create.yml | 60 +++++++++++++ molecule/change-log-path/destroy.yml | 27 ++++++ .../group_vars/tomcat/main.yml | 6 ++ molecule/change-log-path/molecule.yml | 30 +++++++ molecule/change-log-path/playbook.yml | 13 +++ molecule/change-log-path/prepare.yml | 5 ++ molecule/change-log-path/requirements.yml | 5 ++ molecule/change-log-path/tests/dumpall.j2 | 1 + .../tests/test_change-log-path.yml | 42 +++++++++ molecule/change-log-path/verifier.yml | 73 +++++++++++++++ molecule/default/molecule.yml | 4 +- molecule/default/playbook.yml | 7 -- molecule/default/tests/dumpall.j2 | 1 + molecule/default/tests/test_default.yml | 47 ++++++++++ molecule/default/tests/test_tomcat.yml.j2 | 39 -------- molecule/default/verifier.yml | 24 +++-- tasks/config.yml | 1 + tasks/install.yml | 10 ++- templates/logging.properties.j2 | 89 +++++++++++++++++++ templates/server.xml.j2 | 3 +- templates/setenv.sh.j2 | 3 + 31 files changed, 552 insertions(+), 116 deletions(-) create mode 100644 molecule/agent/tests/dumpall.j2 create mode 100644 molecule/agent/tests/test_agent.yml delete mode 100644 molecule/agent/tests/test_tomcat.yml.j2 create mode 100644 molecule/change-log-path/Dockerfile.j2 create mode 100644 molecule/change-log-path/INSTALL.rst create mode 100644 molecule/change-log-path/create.yml create mode 100644 molecule/change-log-path/destroy.yml create mode 100644 molecule/change-log-path/group_vars/tomcat/main.yml create mode 100644 molecule/change-log-path/molecule.yml create mode 100644 molecule/change-log-path/playbook.yml create mode 100644 molecule/change-log-path/prepare.yml create mode 100644 molecule/change-log-path/requirements.yml create mode 100644 molecule/change-log-path/tests/dumpall.j2 create mode 100644 molecule/change-log-path/tests/test_change-log-path.yml create mode 100644 molecule/change-log-path/verifier.yml create mode 100644 molecule/default/tests/dumpall.j2 create mode 100644 molecule/default/tests/test_default.yml delete mode 100644 molecule/default/tests/test_tomcat.yml.j2 create mode 100644 templates/logging.properties.j2 diff --git a/.yamllint b/.yamllint index 3a2255e..0ce2348 100644 --- a/.yamllint +++ b/.yamllint @@ -1,5 +1,9 @@ extends: default +ignore: | + *.travis.yml + test_*.yml + rules: braces: max-spaces-inside: 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index ca2d51d..88b74dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ 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). ## [Unreleased](https://github.com/idealista/tomcat-role/tree/develop) +### Added +- *[#43](https://github.com/idealista/tomcat-role/issues/43) Allow to change log files directory* @sorobon ## [1.5.0](https://github.com/idealista/tomcat-role/tree/1.5.0) ### Added diff --git a/defaults/main.yml b/defaults/main.yml index 6077b3a..4dd46c3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -78,6 +78,23 @@ tomcat_pre_installed_folders_deployed: deployed: true host-manager: deployed: true + ROOT: + deployed: true + +# tomcat_logs_path: /var/log/tomcat +tomcat_logs_level: { + juli: FINE, + catalina: INFO +} + +tomcat_default_log_catalina_out: '"$CATALINA_BASE"/logs' +tomcat_default_log_logging_path: "${catalina.base}/logs" +tomcat_default_log_valves: "logs" + + +# por defecto del script: "$CATALINA_BASE"/logs/catalina.out +# del logging.properties: ${catalina.base}/logs +# de las valves: "logs" ## Agent configuration (optional) diff --git a/molecule/agent/molecule.yml b/molecule/agent/molecule.yml index f3e76a2..a8adfc3 100644 --- a/molecule/agent/molecule.yml +++ b/molecule/agent/molecule.yml @@ -26,5 +26,6 @@ scenario: name: agent verifier: name: goss + enabled: True lint: - name: 'None' + name: flake8 diff --git a/molecule/agent/tests/dumpall.j2 b/molecule/agent/tests/dumpall.j2 new file mode 100644 index 0000000..901b4ff --- /dev/null +++ b/molecule/agent/tests/dumpall.j2 @@ -0,0 +1 @@ +{{ vars | to_nice_yaml }} diff --git a/molecule/agent/tests/test_agent.yml b/molecule/agent/tests/test_agent.yml new file mode 100644 index 0000000..f0aa1a5 --- /dev/null +++ b/molecule/agent/tests/test_agent.yml @@ -0,0 +1,50 @@ +--- + +http: + http://localhost:{{ .Vars.tomcat_http_connector_port }}: + status: 200 + {{ range $key := index .Vars.tomcat_agents_config }} + {{ $key.download_url }}: + status: 200 + {{ end }} + +service: + tomcat: + enabled: true + running: true + +user: + {{ .Vars.tomcat_user }}: + exists: true + groups: + - {{ .Vars.tomcat_group }} + +group: + {{ .Vars.tomcat_group }}: + exists: true + +{{ $user := .Vars.tomcat_user }} +{{ $group := .Vars.tomcat_group }} +{{ $install_path := .Vars.tomcat_install_path }} +port: + tcp:{{ .Vars.tomcat_http_connector_port }}: + listening: true +file: + {{ range $key := index .Vars.tomcat_agents_config }} + {{ $install_path }}: + filetype: directory + exists: true + owner: {{ $user }} + group: {{ $group }} + {{ range $file := index $key.configuration_files}} + {{ $install_path }}/{{ $key.name }}/{{ $file }}: + exists: true + {{ end }} + {{ range $option := index $key.catalina_opts}} + {{ $install_path }}/bin/setagentenv.sh: + exists: true + contains: + - {{ $option }} + {{ end }} + +{{ end }} diff --git a/molecule/agent/tests/test_tomcat.yml.j2 b/molecule/agent/tests/test_tomcat.yml.j2 deleted file mode 100644 index e4a1724..0000000 --- a/molecule/agent/tests/test_tomcat.yml.j2 +++ /dev/null @@ -1,52 +0,0 @@ ---- - -http: - http://localhost:{{ tomcat_http_connector_port }}: - status: 200 - -service: - tomcat: - enabled: true - running: true - -user: - {{ tomcat_user }}: - exists: true - groups: - - {{ tomcat_group }} - -group: - {{ tomcat_group }}: - exists: true - -port: - tcp:{{ tomcat_http_connector_port }}: - listening: true -{% if tomcat_shutdown_port != -1 %} - tcp:{{ tomcat_shutdown_port }}: - listening: true -{% else %} - tcp:8005: - listening: false -{% endif %} -file: -{% for key, value in tomcat_pre_installed_folders_deployed.items() %} - {{ tomcat_webapps_path }}/{{ key }}: - exists: {{ value.deployed }} -{% endfor %} - {{ tomcat_conf_path }}/test/test_file.xml: - exists: true - {{ tomcat_conf_path }}/test/test_template.xml: - exists: true -{% if tomcat_download_wars %} -{% for war in tomcat_war_to_deploy_urls %} - {{ tomcat_webapps_path }}/{{ war.name }}: - exists: true -{% endfor %} -{% endif %} - -command: - java -cp {{ tomcat_install_path }}/lib/catalina.jar org.apache.catalina.util.ServerInfo | grep 'Server version': - exit-status: 0 - stdout: - - "{{ tomcat_version }}" diff --git a/molecule/agent/verifier.yml b/molecule/agent/verifier.yml index 20a129a..0c4c798 100644 --- a/molecule/agent/verifier.yml +++ b/molecule/agent/verifier.yml @@ -24,27 +24,39 @@ - ../../vars/main.yml - "{{ playbook_dir }}/group_vars/tomcat/main.yml" - tasks: - - name: Download and install Goss + - name: Download and install goss get_url: url: "{{ goss_url }}" - dest: "{{ goss_dst }}" + dest: "/usr/local/bin/goss" mode: 0755 - - name: Copy Goss tests to remote - template: + - name: Copy tests to remote + copy: src: "{{ item }}" dest: "{{ goss_test_directory }}/{{ item | basename }}" with_fileglob: - "{{ playbook_dir }}/tests/test_*.yml" + - name: Copy vars in json to template + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/vars.yml.j2" + with_fileglob: + - "{{ playbook_dir }}/tests/dumpall.j2" + delegate_to: localhost + + - name: Copy vars in json to remote + template: + src: "{{ goss_test_directory }}/vars.yml.j2" + dest: "{{ goss_test_directory }}/vars.yml" + - name: Register test files shell: "ls {{ goss_test_directory }}/test_*.yml" register: test_files - name: Execute Goss tests - command: "goss -g {{ item }} validate --format {{ goss_format }}" + command: "goss -g {{ item }} --vars {{ goss_test_directory }}/vars.yml validate --format {{ goss_format }}" register: test_results with_items: "{{ test_files.stdout_lines }}" ignore_errors: true diff --git a/molecule/change-log-path/Dockerfile.j2 b/molecule/change-log-path/Dockerfile.j2 new file mode 100644 index 0000000..f8b4e75 --- /dev/null +++ b/molecule/change-log-path/Dockerfile.j2 @@ -0,0 +1,9 @@ +# Molecule managed + +FROM {{ item.image }} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; fi diff --git a/molecule/change-log-path/INSTALL.rst b/molecule/change-log-path/INSTALL.rst new file mode 100644 index 0000000..e26493b --- /dev/null +++ b/molecule/change-log-path/INSTALL.rst @@ -0,0 +1,16 @@ +******* +Install +******* + +Requirements +============ + +* Docker Engine +* docker-py + +Install +======= + +.. code-block:: bash + + $ sudo pip install docker-py diff --git a/molecule/change-log-path/create.yml b/molecule/change-log-path/create.yml new file mode 100644 index 0000000..10fac31 --- /dev/null +++ b/molecule/change-log-path/create.yml @@ -0,0 +1,60 @@ +--- +- name: Create + hosts: localhost + connection: local + gather_facts: false + no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" + vars: + molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" + molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}" + molecule_scenario_directory: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}" + molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}" + tasks: + - name: Create Dockerfiles from image names + template: + src: "{{ molecule_scenario_directory }}/Dockerfile.j2" + dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}" + with_items: "{{ molecule_yml.platforms }}" + register: platforms + + - name: Discover local Docker images + docker_image_facts: + name: "molecule_local/{{ item.item.name }}" + with_items: "{{ platforms.results }}" + register: docker_images + + - name: Build an Ansible compatible image + docker_image: + path: "{{ molecule_ephemeral_directory }}" + name: "molecule_local/{{ item.item.image }}" + dockerfile: "{{ item.item.dockerfile | default(item.invocation.module_args.dest) }}" + force: "{{ item.item.force | default(true) }}" + with_items: "{{ platforms.results }}" + when: platforms.changed or docker_images.results | map(attribute='images') | select('equalto', []) | list | count >= 0 + + - name: Create molecule instance(s) + docker_container: + name: "{{ item.name }}" + hostname: "{{ item.name }}" + image: "molecule_local/{{ item.image }}" + state: started + recreate: false + log_driver: json-file + command: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}" + privileged: "{{ item.privileged | default(omit) }}" + volumes: "{{ item.volumes | default(omit) }}" + capabilities: "{{ item.capabilities | default(omit) }}" + ports: "{{ item.exposed_ports | default(omit) }}" + ulimits: "{{ item.ulimits | default(omit) }}" + register: server + with_items: "{{ molecule_yml.platforms }}" + async: 7200 + poll: 0 + + - name: Wait for instance(s) creation to complete + async_status: + jid: "{{ item.ansible_job_id }}" + register: docker_jobs + until: docker_jobs.finished + retries: 300 + with_items: "{{ server.results }}" diff --git a/molecule/change-log-path/destroy.yml b/molecule/change-log-path/destroy.yml new file mode 100644 index 0000000..3ce7478 --- /dev/null +++ b/molecule/change-log-path/destroy.yml @@ -0,0 +1,27 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: false + no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" + vars: + molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" + molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}" + tasks: + - name: Destroy molecule instance(s) + docker_container: + name: "{{ item.name }}" + state: absent + force_kill: "{{ item.force_kill | default(true) }}" + register: server + with_items: "{{ molecule_yml.platforms }}" + async: 7200 + poll: 0 + + - name: Wait for instance(s) deletion to complete + async_status: + jid: "{{ item.ansible_job_id }}" + register: docker_jobs + until: docker_jobs.finished + retries: 300 + with_items: "{{ server.results }}" diff --git a/molecule/change-log-path/group_vars/tomcat/main.yml b/molecule/change-log-path/group_vars/tomcat/main.yml new file mode 100644 index 0000000..0a32920 --- /dev/null +++ b/molecule/change-log-path/group_vars/tomcat/main.yml @@ -0,0 +1,6 @@ +--- + +## JAVA +java_implementation: openjdk + +tomcat_logs_path: /var/log/tomcat diff --git a/molecule/change-log-path/molecule.yml b/molecule/change-log-path/molecule.yml new file mode 100644 index 0000000..9b6122b --- /dev/null +++ b/molecule/change-log-path/molecule.yml @@ -0,0 +1,30 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint + +platforms: + - name: tomcat + groups: + - tomcat + image: idealista/java-role:latest + privileged: True + capabilities: + - SYS_ADMIN + volumes: + - '/sys/fs/cgroup:/sys/fs/cgroup:ro' + command: '/lib/systemd/systemd' + +provisioner: + name: ansible + lint: + name: ansible-lint +scenario: + name: change-log-path +verifier: + name: goss + lint: + name: flake8 diff --git a/molecule/change-log-path/playbook.yml b/molecule/change-log-path/playbook.yml new file mode 100644 index 0000000..13ead4d --- /dev/null +++ b/molecule/change-log-path/playbook.yml @@ -0,0 +1,13 @@ +--- +- name: Converge + hosts: tomcat + pre_tasks: + - name: Tomcat | Installing required dependencies + apt: + pkg: "{{ item }}" + state: present + with_items: + - net-tools + roles: + - java + - tomcat-role diff --git a/molecule/change-log-path/prepare.yml b/molecule/change-log-path/prepare.yml new file mode 100644 index 0000000..5358b3b --- /dev/null +++ b/molecule/change-log-path/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare + hosts: all + gather_facts: false + tasks: [] diff --git a/molecule/change-log-path/requirements.yml b/molecule/change-log-path/requirements.yml new file mode 100644 index 0000000..a5fa168 --- /dev/null +++ b/molecule/change-log-path/requirements.yml @@ -0,0 +1,5 @@ +--- + +- src: idealista.java-role + version: 2.0.1 + name: java diff --git a/molecule/change-log-path/tests/dumpall.j2 b/molecule/change-log-path/tests/dumpall.j2 new file mode 100644 index 0000000..901b4ff --- /dev/null +++ b/molecule/change-log-path/tests/dumpall.j2 @@ -0,0 +1 @@ +{{ vars | to_nice_yaml }} diff --git a/molecule/change-log-path/tests/test_change-log-path.yml b/molecule/change-log-path/tests/test_change-log-path.yml new file mode 100644 index 0000000..df2c9ab --- /dev/null +++ b/molecule/change-log-path/tests/test_change-log-path.yml @@ -0,0 +1,42 @@ +--- + +http: + http://localhost:{{ .Vars.tomcat_http_connector_port }}: + status: 200 + +service: + tomcat: + enabled: true + running: true + +user: + {{ .Vars.tomcat_user }}: + exists: true + groups: + - {{ .Vars.tomcat_group }} + +group: + {{ .Vars.tomcat_group }}: + exists: true + +port: + tcp:{{ .Vars.tomcat_http_connector_port }}: + listening: true +file: + {{ .Vars.tomcat_logs_path }}: + filetype: directory + exists: true + owner: {{ .Vars.tomcat_user }} + group: {{ .Vars.tomcat_group }} + {{ .Vars.tomcat_logs_path }}/catalina.out: + exists: true + {{ .Vars.tomcat_logs_path }}/host-manager.{{ .Vars.ansible_date_time.date }}.log: + exists: true + {{ .Vars.tomcat_logs_path }}/manager.{{ .Vars.ansible_date_time.date }}.log: + exists: true + {{ .Vars.tomcat_logs_path }}/catalina.{{ .Vars.ansible_date_time.date }}.log: + exists: true + {{ .Vars.tomcat_logs_path }}/localhost.{{ .Vars.ansible_date_time.date }}.log: + exists: true + {{ .Vars.tomcat_logs_path }}/localhost_access_log.{{ .Vars.ansible_date_time.date }}.txt: + exists: true diff --git a/molecule/change-log-path/verifier.yml b/molecule/change-log-path/verifier.yml new file mode 100644 index 0000000..0c4c798 --- /dev/null +++ b/molecule/change-log-path/verifier.yml @@ -0,0 +1,73 @@ +--- +# This is an example playbook to execute goss tests. +# Tests need distributed to the appropriate ansible host/groups +# prior to execution by `goss validate`. +# +# The goss ansible module is installed with molecule. The ANSIBLE_LIBRARY +# path is updated appropriately on `molecule verify`. + +# Details about ansible module: +# - https://github.com/indusbox/goss-ansible + +- name: Verify + hosts: all + vars: + goss_version: v0.3.5 + goss_arch: amd64 + goss_dst: /usr/local/bin/goss + goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" + goss_test_directory: /tmp + goss_format: documentation + + vars_files: + - ../../defaults/main.yml + - ../../vars/main.yml + - "{{ playbook_dir }}/group_vars/tomcat/main.yml" + + tasks: + - name: Download and install goss + get_url: + url: "{{ goss_url }}" + dest: "/usr/local/bin/goss" + mode: 0755 + + - name: Copy tests to remote + copy: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/{{ item | basename }}" + with_fileglob: + - "{{ playbook_dir }}/tests/test_*.yml" + + - name: Copy vars in json to template + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/vars.yml.j2" + with_fileglob: + - "{{ playbook_dir }}/tests/dumpall.j2" + delegate_to: localhost + + - name: Copy vars in json to remote + template: + src: "{{ goss_test_directory }}/vars.yml.j2" + dest: "{{ goss_test_directory }}/vars.yml" + + - name: Register test files + shell: "ls {{ goss_test_directory }}/test_*.yml" + register: test_files + + - name: Execute Goss tests + command: "goss -g {{ item }} --vars {{ goss_test_directory }}/vars.yml validate --format {{ goss_format }}" + register: test_results + with_items: "{{ test_files.stdout_lines }}" + ignore_errors: true + + - name: Display details about the goss results + debug: + msg: "{{ item.stdout_lines }}" + with_items: "{{ test_results.results }}" + + - name: Fail when tests fail + fail: + msg: "Goss failed to validate" + when: item.rc != 0 + with_items: "{{ test_results.results }}" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 9112e84..b5badf2 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -5,7 +5,6 @@ driver: name: docker lint: name: yamllint - platforms: - name: tomcat groups: @@ -17,7 +16,6 @@ platforms: volumes: - '/sys/fs/cgroup:/sys/fs/cgroup:ro' command: '/lib/systemd/systemd' - provisioner: name: ansible lint: @@ -27,4 +25,4 @@ scenario: verifier: name: goss lint: - name: 'None' + name: flake8 diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml index d04d28f..27563e8 100644 --- a/molecule/default/playbook.yml +++ b/molecule/default/playbook.yml @@ -1,13 +1,6 @@ --- - name: Converge hosts: all - pre_tasks: - - name: Tomcat | Installing required dependencies - apt: - pkg: "{{ item }}" - state: present - with_items: - - net-tools roles: - java - tomcat-role diff --git a/molecule/default/tests/dumpall.j2 b/molecule/default/tests/dumpall.j2 new file mode 100644 index 0000000..901b4ff --- /dev/null +++ b/molecule/default/tests/dumpall.j2 @@ -0,0 +1 @@ +{{ vars | to_nice_yaml }} diff --git a/molecule/default/tests/test_default.yml b/molecule/default/tests/test_default.yml new file mode 100644 index 0000000..58742fa --- /dev/null +++ b/molecule/default/tests/test_default.yml @@ -0,0 +1,47 @@ +http: + http://localhost:{{ .Vars.tomcat_http_connector_port }}: + status: 200 + +service: + tomcat: + enabled: true + running: true + +user: + {{ .Vars.tomcat_user }}: + exists: true + groups: + - {{ .Vars.tomcat_group }} + +group: + {{ .Vars.tomcat_group }}: + exists: true + +port: + tcp:{{ .Vars.tomcat_http_connector_port }}: + listening: true + tcp:{{ .Vars.tomcat_shutdown_port }}: + listening: true + +{{ $webapps_path := .Vars.tomcat_webapps_path }} +file: +{{ range $key, $value := index .Vars.tomcat_pre_installed_folders_deployed }} + {{ $webapps_path }}/{{ $key }}: + exists: {{ $value.deployed }} +{{ end }} + {{ .Vars.tomcat_conf_path }}/test/test_file.xml: + exists: true + {{ .Vars.tomcat_conf_path }}/test/test_template.xml: + exists: true +{{ if ( .Vars.tomcat_download_wars ) and eq .Vars.tomcat_download_wars "true" }} +{{ range index .Vars.tomcat_war_to_deploy_urls }} + {{ $webapps_path }}/{{ .name }}: + exists: true +{{ end }} +{{ end }} + +command: + java -cp {{ .Vars.tomcat_install_path }}/lib/catalina.jar org.apache.catalina.util.ServerInfo | grep 'Server version': + exit-status: 0 + stdout: + - "{{ .Vars.tomcat_version }}" diff --git a/molecule/default/tests/test_tomcat.yml.j2 b/molecule/default/tests/test_tomcat.yml.j2 deleted file mode 100644 index dae9691..0000000 --- a/molecule/default/tests/test_tomcat.yml.j2 +++ /dev/null @@ -1,39 +0,0 @@ ---- - -http: - http://localhost:{{ tomcat_http_connector_port }}: - status: 200 - {% for agent_config in tomcat_agents_config %} - {{ agent_config.download_url }} - status: 200 - {% endfor %} - -service: - tomcat: - enabled: true - running: true - -user: - {{ tomcat_user }}: - exists: true - groups: - - {{ tomcat_group }} - -group: - {{ tomcat_group }}: - exists: true - -port: - tcp:{{ tomcat_http_connector_port }}: - listening: true -{% for agent_config in tomcat_agents_config.items() %} - {{ agent_config.installation_path }} - filetype: directory - exists: true - owner: {{ tomcat_user }} - group: {{ tomcat_group }} - {{ agent_config.installation_path }}/{{ agent_config.configuration_file_name }} - exists: true - {{ agent_config.installation_path }}/{{ agent_config.agent_file }} - exists: true -{% endfor %} diff --git a/molecule/default/verifier.yml b/molecule/default/verifier.yml index 20a129a..0c4c798 100644 --- a/molecule/default/verifier.yml +++ b/molecule/default/verifier.yml @@ -24,27 +24,39 @@ - ../../vars/main.yml - "{{ playbook_dir }}/group_vars/tomcat/main.yml" - tasks: - - name: Download and install Goss + - name: Download and install goss get_url: url: "{{ goss_url }}" - dest: "{{ goss_dst }}" + dest: "/usr/local/bin/goss" mode: 0755 - - name: Copy Goss tests to remote - template: + - name: Copy tests to remote + copy: src: "{{ item }}" dest: "{{ goss_test_directory }}/{{ item | basename }}" with_fileglob: - "{{ playbook_dir }}/tests/test_*.yml" + - name: Copy vars in json to template + template: + src: "{{ item }}" + dest: "{{ goss_test_directory }}/vars.yml.j2" + with_fileglob: + - "{{ playbook_dir }}/tests/dumpall.j2" + delegate_to: localhost + + - name: Copy vars in json to remote + template: + src: "{{ goss_test_directory }}/vars.yml.j2" + dest: "{{ goss_test_directory }}/vars.yml" + - name: Register test files shell: "ls {{ goss_test_directory }}/test_*.yml" register: test_files - name: Execute Goss tests - command: "goss -g {{ item }} validate --format {{ goss_format }}" + command: "goss -g {{ item }} --vars {{ goss_test_directory }}/vars.yml validate --format {{ goss_format }}" register: test_results with_items: "{{ test_files.stdout_lines }}" ignore_errors: true diff --git a/tasks/config.yml b/tasks/config.yml index 3a51552..8ba2083 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -11,6 +11,7 @@ - { 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" } notify: restart tomcat - name: Tomcat | Ensure extra tomcat config file and template paths exists diff --git a/tasks/install.yml b/tasks/install.yml index cb33b35..a46845d 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -10,6 +10,14 @@ group: "{{ tomcat_group }}" shell: /bin/bash +- name: Tomcat | Create logs path + file: + path: "{{ tomcat_logs_path }}" + state: directory + owner: "{{ tomcat_user }}" + group: "{{ tomcat_group }}" + when: tomcat_logs_path is defined + - name: Tomcat | Create install path file: path: "{{ tomcat_install_path }}" @@ -33,7 +41,7 @@ owner: "{{ tomcat_user }}" group: "{{ tomcat_group }}" mode: 0750 - when: 'tomcat_force_reinstall or tomcat_check|failed or tomcat_check.stdout == "Apache Tomcat/{{ tomcat_version }}"' + when: 'tomcat_force_reinstall or tomcat_check|failed or tomcat_check.stdout == "Apache Tomcat/tomcat_version"' - name: Tomcat | Copy Daemon script template: diff --git a/templates/logging.properties.j2 b/templates/logging.properties.j2 new file mode 100644 index 0000000..e4e5696 --- /dev/null +++ b/templates/logging.properties.j2 @@ -0,0 +1,89 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +{% set path = tomcat_logs_path|default(tomcat_default_log_logging_path) %} +{% set manager_deployed = True %} +{% if tomcat_pre_installed_folders_deployed.manager is defined %} + {% set manager_deployed = tomcat_pre_installed_folders_deployed.manager.deployed|default(True) %} +{% endif %} +{% set host_manager_deployed = True %} +{% if tomcat_pre_installed_folders_deployed['host-manager'] is defined %} + {% set host_manager_deployed = tomcat_pre_installed_folders_deployed['host-manager'].deployed|default(True) %} +{% endif %} + +handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, {% if manager_deployed %}3manager.org.apache.juli.AsyncFileHandler,{% endif %} {% if host_manager_deployed %}4host-manager.org.apache.juli.AsyncFileHandler,{% endif %} java.util.logging.ConsoleHandler + +.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler + +############################################################ +# Handler specific properties. +# Describes specific configuration info for Handlers. +############################################################ + +1catalina.org.apache.juli.AsyncFileHandler.level = {{ tomcat_logs_level.juli }} +1catalina.org.apache.juli.AsyncFileHandler.directory = {{ path }} +1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina. + +2localhost.org.apache.juli.AsyncFileHandler.level = {{ tomcat_logs_level.juli }} +2localhost.org.apache.juli.AsyncFileHandler.directory = {{ path }} +2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost. + +{% if manager_deployed %} +3manager.org.apache.juli.AsyncFileHandler.level = {{ tomcat_logs_level.juli }} +3manager.org.apache.juli.AsyncFileHandler.directory = {{ path }} +3manager.org.apache.juli.AsyncFileHandler.prefix = manager. +{% endif %} + +{% if host_manager_deployed %} +4host-manager.org.apache.juli.AsyncFileHandler.level = {{ tomcat_logs_level.juli }} +4host-manager.org.apache.juli.AsyncFileHandler.directory = {{ path }} +4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager. +{% endif %} + +java.util.logging.ConsoleHandler.level = {{ tomcat_logs_level.juli }} +java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter + + +############################################################ +# Facility specific properties. +# Provides extra control for each logger. +############################################################ + +org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = {{ tomcat_logs_level.catalina }} +org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler + +{% if manager_deployed %} +org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = {{ tomcat_logs_level.catalina }} +org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler +{% endif %} + +{% if host_manager_deployed %} +org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = {{ tomcat_logs_level.catalina }} +org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler +{% endif %} + +# For example, set the org.apache.catalina.util.LifecycleBase logger to log +# each component that extends LifecycleBase changing state: +#org.apache.catalina.util.LifecycleBase.level = FINE + +# To see debug messages in TldLocationsCache, uncomment the following line: +#org.apache.jasper.compiler.TldLocationsCache.level = FINE + +# To see debug messages for HTTP/2 handling, uncomment the following line: +#org.apache.coyote.http2.level = FINE + +# To see debug messages for WebSocket handling, uncomment the following line: +#org.apache.tomcat.websocket.level = FINE diff --git a/templates/server.xml.j2 b/templates/server.xml.j2 index 66db5b2..9efb079 100644 --- a/templates/server.xml.j2 +++ b/templates/server.xml.j2 @@ -132,7 +132,8 @@ - diff --git a/templates/setenv.sh.j2 b/templates/setenv.sh.j2 index 7654928..aeeb84c 100644 --- a/templates/setenv.sh.j2 +++ b/templates/setenv.sh.j2 @@ -11,3 +11,6 @@ elif [ -r "$CATALINA_HOME/bin/setagentenv.sh" ]; then . "$CATALINA_HOME/bin/setagentenv.sh" fi {% endif %} + +{% set path = tomcat_logs_path|default(tomcat_default_log_catalina_out) %} +export CATALINA_OUT={{ path }}/catalina.out From 6e2e38ebb240d7239814e0f0e133f68a128c459a Mon Sep 17 00:00:00 2001 From: Santiago Orobon Date: Wed, 14 Feb 2018 14:52:55 +0100 Subject: [PATCH 2/3] [#43] Review changes --- defaults/main.yml | 6 +----- molecule/agent/verifier.yml | 2 +- molecule/change-log-path/verifier.yml | 2 +- molecule/default/verifier.yml | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 4dd46c3..7fe7e8d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -81,6 +81,7 @@ tomcat_pre_installed_folders_deployed: ROOT: deployed: true +## Logs path (optional, by default its used tomcat_default_log_catalina_out, tomcat_default_log_logging_path and tomcat_default_log_valves) # tomcat_logs_path: /var/log/tomcat tomcat_logs_level: { juli: FINE, @@ -91,11 +92,6 @@ tomcat_default_log_catalina_out: '"$CATALINA_BASE"/logs' tomcat_default_log_logging_path: "${catalina.base}/logs" tomcat_default_log_valves: "logs" - -# por defecto del script: "$CATALINA_BASE"/logs/catalina.out -# del logging.properties: ${catalina.base}/logs -# de las valves: "logs" - ## Agent configuration (optional) # tomcat_agents_required_libs: diff --git a/molecule/agent/verifier.yml b/molecule/agent/verifier.yml index 0c4c798..6f0d7fa 100644 --- a/molecule/agent/verifier.yml +++ b/molecule/agent/verifier.yml @@ -28,7 +28,7 @@ - name: Download and install goss get_url: url: "{{ goss_url }}" - dest: "/usr/local/bin/goss" + dest: "{{ goss_dst }}" mode: 0755 - name: Copy tests to remote diff --git a/molecule/change-log-path/verifier.yml b/molecule/change-log-path/verifier.yml index 0c4c798..6f0d7fa 100644 --- a/molecule/change-log-path/verifier.yml +++ b/molecule/change-log-path/verifier.yml @@ -28,7 +28,7 @@ - name: Download and install goss get_url: url: "{{ goss_url }}" - dest: "/usr/local/bin/goss" + dest: "{{ goss_dst }}" mode: 0755 - name: Copy tests to remote diff --git a/molecule/default/verifier.yml b/molecule/default/verifier.yml index 0c4c798..6f0d7fa 100644 --- a/molecule/default/verifier.yml +++ b/molecule/default/verifier.yml @@ -28,7 +28,7 @@ - name: Download and install goss get_url: url: "{{ goss_url }}" - dest: "/usr/local/bin/goss" + dest: "{{ goss_dst }}" mode: 0755 - name: Copy tests to remote From bb9e06d92e2517400e4995bbf467a43b0704b157 Mon Sep 17 00:00:00 2001 From: Santiago Orobon Date: Wed, 14 Feb 2018 17:58:18 +0100 Subject: [PATCH 3/3] release 1.6.0 --- CHANGELOG.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88b74dc..f5ba3db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ 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). ## [Unreleased](https://github.com/idealista/tomcat-role/tree/develop) + +## [1.6.0](https://github.com/idealista/tomcat-role/tree/1.6.0) ### Added - *[#43](https://github.com/idealista/tomcat-role/issues/43) Allow to change log files directory* @sorobon @@ -11,7 +13,6 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch - *[#40](https://github.com/idealista/tomcat-role/issues/40) Support for addons like java-agents* @sorobon ## [1.4.0](https://github.com/idealista/tomcat-role/tree/1.4.0) - ### Added - *[#29](https://github.com/idealista/tomcat-role/issues/29) Upgrade molecule* @jdvr - *[#26](https://github.com/idealista/tomcat-role/issues/26) Fix to copy extra configuration recursively* @dortegau @@ -19,33 +20,27 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch - *[#21](https://github.com/idealista/tomcat-role/issues/21) Remove pre-installed folders from webapps* @dortegau ## [1.3.1](https://github.com/idealista/tomcat-role/tree/1.3.1) - ### Fixed - *[#17](https://github.com/idealista/tomcat-role/issues/17) Fix war user and group after download* @jdvr ## [1.3.0](https://github.com/idealista/tomcat-role/tree/1.3.0) - ### Added - *[#13](https://github.com/idealista/tomcat-role/issues/13) Add maven repository as a valid download war source* @jdvr ## [1.2.0](https://github.com/idealista/tomcat-role/tree/1.2.0) - ### Added - *[#5](https://github.com/idealista/tomcat-role/issues/5) Add a name for the downloaded war during deployment* @jdvr ## [1.1.2](https://github.com/idealista/tomcat-role/tree/1.1.2) - ### Fixed - *[#8](https://github.com/idealista/tomcat-role/issues/8) Fix systemd startup* @jmonterrubio - *[#6](https://github.com/idealista/tomcat-role/issues/6) Fix conf directory template copy* @jnogol ## [1.1.0](https://github.com/idealista/tomcat-role/tree/1.1.0) - ### Added - *[#1](https://github.com/idealista/tomcat-role/issues/1) Add deploy task* @jdvr ## [1.0.0](https://github.com/idealista/tomcat-role/tree/1.0.0) - ### Added - *First release*