- name: Add gpg package apt: name: gpg - name: Add gpg keys for consul environment: http_proxy: "{{ consul_install_http_proxy | default(omit) }}" https_proxy: "{{ consul_install_https_proxy | default(omit) }}" ansible.builtin.apt_key: url: "{{ item.url }}" keyring: "{{ item.keyring }}" loop: "{{ consul_apt_key }}" - name: Add Hashicorp repository environment: http_proxy: "{{ consul_install_http_proxy | default(omit) }}" https_proxy: "{{ consul_install_https_proxy | default(omit) }}" apt_repository: repo: "{{ item.repo }}" state: present filename: "{{ item.filename }}" update_cache: yes loop: "{{ consul_apt_repository }}" - 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 - name: Mask Consul before install ansible.builtin.systemd: name: "{{ consul_package_name }}" masked: yes 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 }}" environment: http_proxy: "{{ consul_install_http_proxy | default(omit) }}" https_proxy: "{{ consul_install_https_proxy | default(omit) }}" apt: name: "{{ consul_package }}-{{ consul_version_build }}" update_cache: yes register: consul_setup when: consul_package_name not in ansible_facts.packages - name: "Update {{ consul_package_name }}-{{ consul_version }}-{{ consul_version_build }}" environment: http_proxy: "{{ consul_install_http_proxy | default(omit) }}" https_proxy: "{{ consul_install_https_proxy | default(omit) }}" 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: content: "" dest: /etc/consul.d/consul.env owner: consul group: consul