update consul descovery and rhel/debian support

This commit is contained in:
ace 2023-02-08 01:23:29 +03:00
parent c9929c4c87
commit 9e46c26746
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
3 changed files with 26 additions and 8 deletions

View File

@ -16,25 +16,41 @@
update_cache: yes
loop: "{{ consul_apt_repository }}"
- name: Check if Consul is installed
ansible.builtin.shell: dpkg-query -l {{ consul_package_name }} 2>&1 | grep {{ consul_version }}
ignore_errors: True
register: is_consul
changed_when: is_consul.rc != 0
failed_when: False
- name: Gather packages
package_facts:
manager: auto
- name: Set fact about Consul package
set_fact:
consul_installed_package: "{{ ansible_facts.packages[consul_package_name][0]['name'] }}"
when: consul_package_name in ansible_facts.packages
- debug:
msg: "{{ ansible_facts.packages[consul_package_name][0]['version'] }}"
when: consul_installed_package is defined
- name: Mask Consul before install
ansible.builtin.systemd:
name: "{{ consul_package_name }}"
masked: yes
when: is_consul.rc != 0
when: consul_package_name not in ansible_facts.packages or ansible_facts.packages[consul_package_name][0]['version'] != (consul_version + "-" + consul_version_build)
- name: "Install {{ consul_package_name }}-{{ consul_version }}-{{ consul_version_build }}"
apt:
name: "{{ consul_package }}-{{ consul_version_build }}"
update_cache: yes
register: consul_setup
when: is_consul.rc != 0
when: consul_package_name not in ansible_facts.packages
- name: "Update {{ consul_package_name }}-{{ consul_version }}-{{ consul_version_build }}"
apt:
name: "{{ consul_package }}-{{ consul_version_build }}"
update_cache: yes
register: consul_update
notify: Restart consul
when:
- consul_package_name in ansible_facts.packages
- ansible_facts.packages[consul_package_name][0]['version'] != (consul_version + "-" + consul_version_build)
- name: Fix "/etc/consul.d/consul.env"
copy:

View File

@ -7,5 +7,6 @@ consul_apt_repository:
- repo: deb [arch=amd64] https://apt.releases.hashicorp.com {{ ansible_distribution_release }} main
filename: hashicorp
consul_version_build: "1"
consul_package_name_regex: "{{ consul_package_name }}-{{ consul_version }}-{{ consul_version_build }}"
consul_ssl_update_ca_command: "update-ca-certificates --fresh"
consul_ssl_ca_trust_dir: "/usr/local/share/ca-certificates"

View File

@ -1,3 +1,4 @@
consul_package: "{{ consul_package_name }}-{{ consul_version }}"
consul_package_name_regex: "{{ consul_package }}"
consul_ssl_update_ca_command: "update-ca-trust extract"
consul_ssl_ca_trust_dir: "/etc/pki/ca-trust/source/anchors"