Skip to content

Commit

Permalink
[#66] Improve agents management
Browse files Browse the repository at this point in the history
  • Loading branch information
sorobon committed May 14, 2020
1 parent dccde19 commit 8262a14
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch
### Changed
- *[#61](https://github.com/idealista/tomcat_role/issues/61) Update molecule to 3.x* @sorobon
- *[#63](https://github.com/idealista/tomcat_role/issues/63) Rename role to tomcat_role* @sorobon
- *[#66](https://github.com/idealista/tomcat_role/issues/66) Improve agents management* @sorobon

## [1.8.0](https://github.com/idealista/tomcat_role/tree/1.8.0)
[Full Changelog](https://github.com/idealista/tomcat_role/compare/1.7.0...1.8.0)
Expand Down
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,15 @@ tomcat_default_log_logging_path: "${catalina.base}/logs"
tomcat_default_log_valves: "logs"

## Agent configuration (optional)

tomcat_agents_force_reinstall: false
# tomcat_agents_required_libs:
# - unzip
# - apt-transport-https

# tomcat_agents_config:
# - name: "agent_name"
# download_url: "download_url"
# version: "x.x.x"
# catalina_opts:
# - '-javaagent:{{ tomcat_install_path }}/agent_name/agent_file'
# configuration_files:
Expand Down
1 change: 1 addition & 0 deletions molecule/default/group_vars/tomcat/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tomcat_agents_required_libs:
tomcat_agents_config:
- name: "newrelic"
download_url: "http://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip"
version: "5.11.0"
catalina_opts:
- '-javaagent:{{ tomcat_install_path }}/newrelic/newrelic.jar'
configuration_files:
Expand Down
46 changes: 36 additions & 10 deletions tasks/agent.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
---

- name: Tomcat agent installation | Install required packages
- name: Tomcat | agent installation | Install required packages
apt:
pkg: "{{ item }}"
state: present
with_items: '{{ tomcat_agents_required_libs }}'

- name: Tomcat agent installation | Ensure install path
- name: Tomcat | agent installation | Ensure install path
file:
path: "{{ tomcat_install_path }}/{{ item.name }}"
state: directory
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
with_items: '{{ tomcat_agents_config }}'

- name: Tomcat agent installation | Check if agent is installed
- name: Tomcat | agent installation | Check if agent is installed
stat:
path: "{{ tomcat_install_path }}/{{ item.0.name }}/{{ item.1 | basename }}"
register: agent_file_exists
with_subelements:
- "{{ tomcat_agents_config }}"
- catalina_opts

- name: Tomcat agent installation | Download agent
- name: Tomcat | agent installation | Check agent version
command: "cat {{ tomcat_install_path }}/{{ item.0.name }}/version.txt"
register: agent_version_checked
changed_when: false
ignore_errors: true
with_subelements:
- "{{ tomcat_agents_config }}"
- catalina_opts
- debug:
msg: "mierduza extrema {{ agent_version_checked }} "

- name: Tomcat | agent installation | Download agent
get_url:
dest: "/tmp"
url: "{{ item.download_url }}"
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
register: agent_downloaded
with_items: '{{ tomcat_agents_config }}'
loop: "{{ tomcat_agents_config|flatten(levels=1) }}"
loop_control:
index_var: index
when: tomcat_agents_force_reinstall or not agent_file_exists.results[index].stat.exists or item.version != agent_version_checked.results[index].stdout or agent_version_checked.results[index].failed


- name: Tomcat agent installation | Unarchive package
- name: Tomcat | agent installation | Unarchive package
unarchive:
src: "/tmp/{{ item.download_url | basename }}"
dest: "{{ tomcat_install_path }}"
Expand All @@ -44,30 +59,41 @@
tags:
- skip_ansible_lint

- name: Tomcat agent installation | Check configuration files
- name: Tomcat | agent installation | Copy version number file
template:
src: "agents/version.txt.j2"
dest: "{{ tomcat_install_path }}/{{ item.name }}/version.txt"
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
mode: 0644
with_items: '{{ tomcat_agents_config }}'

- name: Tomcat | agent installation | Check configuration files
set_fact:
tomcat_agent_configuration: "{{ tomcat_agent_configuration|default([]) + [ {'name': item.0.name, 'file': item.1, 'params': item.0.params}] }}"
with_subelements:
- "{{ tomcat_agents_config }}"
- configuration_files

- name: Tomcat agent installation | Configure the Java agent
- name: Tomcat | agent installation | Configure the Java agent
template:
src: "{{ playbook_dir }}/templates/tomcat/agents/{{ item.name }}/{{ item.file }}.j2"
dest: "{{ tomcat_install_path }}/{{ item.name }}/{{ item.file }}"
owner: "{{ tomcat_user }}"
group: "{{ tomcat_group }}"
when: agent_downloaded.changed
notify: restart tomcat
with_items:
- '{{ tomcat_agent_configuration }}'

- name: Tomcat agent installation | Check catalina options
- name: Tomcat | agent installation | Check catalina options
set_fact:
tomcat_agent_catalina_opts: "{% set tomcat_agent_catalina_opts = tomcat_agent_catalina_opts|default([]) + [item.1] %}{{ tomcat_agent_catalina_opts|list }}"
with_subelements:
- "{{ tomcat_agents_config }}"
- catalina_opts

- name: Tomcat agent installation | Configure catalina options
- name: Tomcat | agent installation | Configure catalina options
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
Expand Down
1 change: 1 addition & 0 deletions templates/agents/version.txt.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ item.version }}

0 comments on commit 8262a14

Please sign in to comment.