2022-07-28 14:14:26 +00:00
- name : Add gpg package
apt :
name : gpg
- name : Add gpg keys for consul
ansible.builtin.apt_key :
url : "{{ item.url }}"
keyring : "{{ item.keyring }}"
loop : "{{ consul_apt_key }}"
- name : Add Hashicorp repository
apt_repository :
repo : "{{ item.repo }}"
state : present
filename : "{{ item.filename }}"
update_cache : yes
loop : "{{ consul_apt_repository }}"
2023-02-07 22:23:29 +00:00
- 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
2022-07-28 14:14:26 +00:00
- name : Mask Consul before install
ansible.builtin.systemd :
name : "{{ consul_package_name }}"
masked : yes
2023-02-07 22:23:29 +00:00
when : consul_package_name not in ansible_facts.packages or ansible_facts.packages[consul_package_name][0]['version'] != (consul_version + "-" + consul_version_build)
2022-07-28 14:14:26 +00:00
2023-02-07 20:11:11 +00:00
- name : "Install {{ consul_package_name }}-{{ consul_version }}-{{ consul_version_build }}"
2022-07-28 14:14:26 +00:00
apt :
2023-02-07 20:11:11 +00:00
name : "{{ consul_package }}-{{ consul_version_build }}"
2022-07-28 14:14:26 +00:00
update_cache : yes
register : consul_setup
2023-02-07 22:23:29 +00:00
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)
2022-07-28 14:14:26 +00:00
- name : Fix "/etc/consul.d/consul.env"
copy :
content : ""
dest : /etc/consul.d/consul.env
owner : consul
group : consul