From 8aa789565a3680b9286ea12ea2e737791ebf6642 Mon Sep 17 00:00:00 2001 From: Santiago Orobon Date: Wed, 20 May 2020 20:20:22 +0200 Subject: [PATCH] [#112] Improve agents management --- CHANGELOG.md | 1 + defaults/main.yml | 2 +- tasks/agent.yml | 43 +++++++++++++++++++++------------ templates/agents/version.txt.j2 | 1 + 4 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 templates/agents/version.txt.j2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 460c681..f07a66b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - *[#110](https://github.com/idealista/solrcloud_role/issues/110) Role fully compatible with solr 8.5.1* @sorobon - *[#109](https://github.com/idealista/solrcloud_role/issues/109) Migration to molecule 3.x* @sorobon - *[#113](https://github.com/idealista/solrcloud_role/issues/113) Rename role to solrcloud_role* @sorobon +- *[#112](https://github.com/idealista/solrcloud_role/issues/112) Improve agents management* @sorobon ### Fixed - *[#106](https://github.com/idealista/solrcloud_role/issues/106) Extra space in SOLR_ULIMIT_CHECKS var in solr.in.sh.j2* ### Removed diff --git a/defaults/main.yml b/defaults/main.yml index e4192a7..2e6c403 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -177,7 +177,7 @@ solr_backup_repository: # type: int ## Agent configuration (optional) - +solr_agents_force_reinstall: false solr_agents_template_path: "{{ playbook_dir }}/templates/agents" # solr_agents_required_libs: diff --git a/tasks/agent.yml b/tasks/agent.yml index 0a5f504..ea4b37b 100644 --- a/tasks/agent.yml +++ b/tasks/agent.yml @@ -22,18 +22,31 @@ - "{{ solr_agents_config }}" - vm_opts +- name: SolrCloud | Agent installation | Check agent version + command: "cat {{ solr_installation_dir }}/{{ item.0.name }}/version.txt" + register: agent_version_checked + changed_when: false + ignore_errors: true + with_subelements: + - "{{ solr_agents_config }}" + - vm_opts + - name: SolrCloud | Agent installation | Download agent get_url: - dest: "/tmp" + dest: "{{ solr_tmp_basedir }}" url: "{{ item.download_url }}" owner: "{{ solr_user }}" group: "{{ solr_group }}" register: agent_downloaded - with_items: '{{ solr_agents_config }}' + loop: "{{ solr_agents_config|flatten(levels=1) }}" + loop_control: + index_var: index + when: solr_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: SolrCloud | Agent installation | Unarchive package unarchive: - src: "/tmp/{{ item.download_url | basename }}" + src: "{{ solr_tmp_basedir }}/{{ item.download_url | basename }}" dest: "{{ solr_installation_dir }}" remote_src: true owner: "{{ solr_user }}" @@ -44,6 +57,15 @@ tags: - skip_ansible_lint +- name: SolrCloud | Agent installation | Copy version number file + template: + src: "agents/version.txt.j2" + dest: "{{ solr_installation_dir }}/{{ item.name }}/version.txt" + owner: "{{ solr_user }}" + group: "{{ solr_group }}" + mode: 0644 + with_items: '{{ solr_agents_config }}' + - name: SolrCloud | Agent installation | Check configuration files set_fact: solr_agent_configuration: "{{ solr_agent_configuration|default([]) + [ {'name': item.0.name, 'file': item.1, 'params': item.0.params}] }}" @@ -57,6 +79,8 @@ dest: "{{ solr_installation_dir }}/{{ item.name }}/{{ item.file }}" owner: "{{ solr_user }}" group: "{{ solr_group }}" + when: agent_downloaded.changed + notify: restart SolrCloud with_items: - '{{ solr_agent_configuration }}' @@ -66,16 +90,3 @@ with_subelements: - "{{ solr_agents_config }}" - vm_opts - -# - name: SolrCloud | Agent installation | Check previous solr installation -# stat: -# path: /etc/default/solr.in.sh -# register: agent_previous_solr_exists - -# - name: SolrCloud | Agent installation | Configuring SolrCloud init script with agents config -# template: -# src: "{{ solr_templates_dir }}/solr.in.sh.j2" -# dest: /etc/default/solr.in.sh -# force: true -# when: agent_previous_solr_exists.stat is defined and agent_previous_solr_exists.stat.exists == True -# notify: restart SolrCloud diff --git a/templates/agents/version.txt.j2 b/templates/agents/version.txt.j2 new file mode 100644 index 0000000..199c179 --- /dev/null +++ b/templates/agents/version.txt.j2 @@ -0,0 +1 @@ +{{ item.version }}