From aab7090e4d7a3bc5947166931a23aa0639d188fc Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Tue, 23 Feb 2021 09:24:07 +0000 Subject: [PATCH] Use ansible_facts[] instead of fact variables See https://github.com/ansible/ansible/issues/73654 Change-Id: I3e48000a4685d4df46cd60113ce4c0c02b63dc0c --- defaults/main.yml | 4 ++-- handlers/main.yml | 6 +++--- meta/main.yml | 2 +- tasks/main.yml | 10 +++++----- tasks/repo_install.yml | 10 +++++----- templates/lsyncd.defaults.j2 | 4 ++-- vars/redhat-7.yml | 2 +- vars/redhat-8.yml | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index f2ee45b..c651582 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,14 +18,14 @@ debug: False ## Cap the maximum number of threads / workers when a user value is unspecified. repo_nginx_threads_max: 16 -repo_nginx_threads: "{{ [[ansible_processor_vcpus|default(2) // 2, 1] | max, repo_nginx_threads_max] | min }}" +repo_nginx_threads: "{{ [[ansible_facts['processor_vcpus']|default(2) // 2, 1] | max, repo_nginx_threads_max] | min }}" ## APT Cache Options cache_timeout: 600 ## Centos EPEL repository options repo_centos_epel_mirror: "{{ centos_epel_mirror | default('http://download.fedoraproject.org/pub/epel') }}" -repo_centos_epel_key: "{{ centos_epel_key | default('http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-' ~ ansible_distribution_major_version) }}" +repo_centos_epel_key: "{{ centos_epel_key | default('http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-' ~ ansible_facts['distribution_major_version']) }}" ## Centos NGINX repository options repo_centos_nginx_mirror: "{{ centos_nginx_mirror | default('http://nginx.org/packages/centos/$releasever/$basearch') }}" diff --git a/handlers/main.yml b/handlers/main.yml index ebfe7a6..16f03b6 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -18,7 +18,7 @@ name: "nginx" enabled: yes state: restarted - daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}" + daemon_reload: "{{ (ansible_facts['service_mgr'] == 'systemd') | ternary('yes', omit) }}" register: _restart until: _restart is success retries: 5 @@ -29,7 +29,7 @@ name: "{{ rsyncd_service_name }}" enabled: yes state: restarted - daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}" + daemon_reload: "{{ (ansible_facts['service_mgr'] == 'systemd') | ternary('yes', omit) }}" register: _restart until: _restart is success retries: 5 @@ -40,7 +40,7 @@ name: "lsyncd" enabled: yes state: restarted - daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}" + daemon_reload: "{{ (ansible_facts['service_mgr'] == 'systemd') | ternary('yes', omit) }}" register: _restart until: _restart is success retries: 5 diff --git a/meta/main.yml b/meta/main.yml index 9a74cbf..f80bcc8 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -37,4 +37,4 @@ galaxy_info: dependencies: - role: apt_package_pinning when: - - ansible_pkg_mgr == 'apt' + - ansible_facts['pkg_mgr'] == 'apt' diff --git a/tasks/main.yml b/tasks/main.yml index c52dd15..78e58a0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -16,11 +16,11 @@ - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: - - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml" - - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml" - - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml" - - "{{ ansible_distribution | lower }}.yml" - - "{{ ansible_os_family | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" + - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}.yml" + - "{{ ansible_facts['os_family'] | lower }}.yml" tags: - always diff --git a/tasks/repo_install.yml b/tasks/repo_install.yml index 3974bf2..36f92af 100644 --- a/tasks/repo_install.yml +++ b/tasks/repo_install.yml @@ -18,7 +18,7 @@ key: "{{ repo_centos_epel_key }}" state: present when: - - ansible_pkg_mgr in ['yum', 'dnf'] + - ansible_facts['pkg_mgr'] in ['yum', 'dnf'] register: _add_yum_keys until: _add_yum_keys is success retries: 5 @@ -34,7 +34,7 @@ state: present includepkgs: 'lsyncd' when: - - ansible_pkg_mgr in ['yum', 'dnf'] + - ansible_facts['pkg_mgr'] in ['yum', 'dnf'] register: install_epel_repo until: install_epel_repo is success retries: 5 @@ -47,7 +47,7 @@ baseurl: "{{ repo_centos_nginx_mirror }}" gpgkey: "{{ repo_centos_nginx_key }}" when: - - ansible_pkg_mgr in ['yum', 'dnf'] + - ansible_facts['pkg_mgr'] in ['yum', 'dnf'] register: add_nginx_repo until: add_nginx_repo is success retries: 5 @@ -57,8 +57,8 @@ package: name: "{{ repo_server_distro_packages | reject('equalto', '') | list }}" state: "{{ repo_server_package_state }}" - update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}" - cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" + update_cache: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}" + cache_valid_time: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary(cache_timeout, omit) }}" register: install_packages until: install_packages is success retries: 5 diff --git a/templates/lsyncd.defaults.j2 b/templates/lsyncd.defaults.j2 index fdbfbbd..e823dbe 100644 --- a/templates/lsyncd.defaults.j2 +++ b/templates/lsyncd.defaults.j2 @@ -1,5 +1,5 @@ -{% if ansible_os_family == 'Debian' %} +{% if ansible_facts['os_family'] == 'Debian' %} DAEMON_ARGS="$DAEMON_ARGS -insist" -{% elif ansible_os_family == 'RedHat' %} +{% elif ansible_facts['os_family'] == 'RedHat' %} LSYNCD_OPTIONS="{{ repo_lsyncd_config_file }}" {% endif %} diff --git a/vars/redhat-7.yml b/vars/redhat-7.yml index d0f78ff..6064b87 100644 --- a/vars/redhat-7.yml +++ b/vars/redhat-7.yml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -repo_centos_epel_base: "{{ ansible_distribution_major_version ~ '/' ~ ansible_architecture }}" +repo_centos_epel_base: "{{ ansible_facts['distribution_major_version'] ~ '/' ~ ansible_facts['architecture'] }}" systemd_utils_prefix: "/lib/systemd" diff --git a/vars/redhat-8.yml b/vars/redhat-8.yml index 6bc085f..20e4b60 100644 --- a/vars/redhat-8.yml +++ b/vars/redhat-8.yml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -repo_centos_epel_base: "{{ ansible_distribution_major_version ~ '/Everything/' ~ ansible_architecture }}" +repo_centos_epel_base: "{{ ansible_facts['distribution_major_version'] ~ '/Everything/' ~ ansible_facts['architecture'] }}" systemd_utils_prefix: "/lib/systemd"