From a47e6aecd1ee938d8c97eda02e65df63ff5fc530 Mon Sep 17 00:00:00 2001 From: Adar Nimrod Date: Sat, 19 Jun 2021 14:37:48 +0300 Subject: [PATCH] Use the newer ansible_facts format. --- roles/debian_server/tasks/btrfs.yml | 2 +- roles/debian_server/tasks/docker.yml | 2 +- roles/debian_server/tasks/main.yml | 8 ++++---- roles/debian_server/tasks/toolbox.yml | 4 ++-- roles/debian_server/vars/main.yml | 2 +- roles/router/handlers/main.yaml | 2 +- roles/router/tasks/main.yaml | 2 +- roles/wap/tasks/main.yaml | 10 ++++++---- roles/wap/templates/daily.j2 | 3 ++- tasks/renew-cert.yaml | 6 +++--- update.yaml | 6 +++--- 11 files changed, 25 insertions(+), 22 deletions(-) diff --git a/roles/debian_server/tasks/btrfs.yml b/roles/debian_server/tasks/btrfs.yml index f53ba7d..013e7f9 100644 --- a/roles/debian_server/tasks/btrfs.yml +++ b/roles/debian_server/tasks/btrfs.yml @@ -10,7 +10,7 @@ - name: Create btrfs scrub services # yamllint disable rule:line-length loop: &btrfs_devices |- - {{ ansible_mounts|selectattr("fstype", "equalto", "btrfs")|map(attribute="device")|unique }} + {{ ansible_facts.mounts|selectattr("fstype", "equalto", "btrfs")|map(attribute="device")|unique }} # yamllint enable rule:line-length ansible.builtin.template: dest: /etc/systemd/system/scrub{{ name }}.service diff --git a/roles/debian_server/tasks/docker.yml b/roles/debian_server/tasks/docker.yml index 60b2af8..118e3bc 100644 --- a/roles/debian_server/tasks/docker.yml +++ b/roles/debian_server/tasks/docker.yml @@ -55,7 +55,7 @@ owner: root - name: Allow unprivileged user namespaces - when: ansible_facts["distribution_major_version"] < 11 + when: ansible_facts.distribution_major_version|int < 11 ansible.posix.sysctl: name: kernel/unprivileged_userns_clone state: present diff --git a/roles/debian_server/tasks/main.yml b/roles/debian_server/tasks/main.yml index 2568d8f..e66f448 100644 --- a/roles/debian_server/tasks/main.yml +++ b/roles/debian_server/tasks/main.yml @@ -2,9 +2,9 @@ - name: Verify assertions assert: that: - - ansible_distribution == "Debian" - - ansible_distribution_major_version|int >= 10 - - ansible_service_mgr == "systemd" + - ansible_facts.distribution == "Debian" + - ansible_facts.distribution_major_version|int >= 10 + - ansible_facts.service_mgr == "systemd" - name: Enable the backports repo loop: @@ -12,7 +12,7 @@ - deb-src apt_repository: # yamllint disable-line rule:line-length - repo: '{{ item }} http://deb.debian.org/debian {{ ansible_distribution_release }}-backports main contrib non-free' + repo: '{{ item }} http://deb.debian.org/debian {{ ansible_facts.distribution_release }}-backports main contrib non-free' state: present update_cache: true diff --git a/roles/debian_server/tasks/toolbox.yml b/roles/debian_server/tasks/toolbox.yml index ef7e6d4..ccf999e 100644 --- a/roles/debian_server/tasks/toolbox.yml +++ b/roles/debian_server/tasks/toolbox.yml @@ -1,7 +1,7 @@ --- - name: Install Podman from the Kubic repository # yamllint disable-line rule:line-length - when: ansible_distribution_release is in ["buster", "bionic", "focal", "hera", "odin"] + when: ansible_facts.distribution_release is in ["buster", "bionic", "focal", "hera", "odin"] block: - name: Assertions assert: @@ -30,7 +30,7 @@ update_cache: true - name: Install newer libseccomp2 from the backports repository - when: ansible_distribution_release == "buster" + when: ansible_facts.distribution_release == "buster" apt: cache_valid_time: 3600 default_release: buster-backports diff --git a/roles/debian_server/vars/main.yml b/roles/debian_server/vars/main.yml index a1257de..5f233a3 100644 --- a/roles/debian_server/vars/main.yml +++ b/roles/debian_server/vars/main.yml @@ -12,4 +12,4 @@ toolbox_podman_repo_base_url_mapping: odin: *focal toolbox_podman_repo_base_url: |- - {{ toolbox_podman_repo_base_url_mapping[ansible_distribution_release] }} + {{ toolbox_podman_repo_base_url_mapping[ansible_facts.distribution_release] }} diff --git a/roles/router/handlers/main.yaml b/roles/router/handlers/main.yaml index c95d484..a9f4fea 100644 --- a/roles/router/handlers/main.yaml +++ b/roles/router/handlers/main.yaml @@ -63,7 +63,7 @@ - name: Message about restarting the machine debug: - msg: The {{ ansible_hostname }} needs to be restarted + msg: The {{ ansible_facts.hostname }} needs to be restarted verbosity: 0 - name: Stop the audio server diff --git a/roles/router/tasks/main.yaml b/roles/router/tasks/main.yaml index e68960a..c4224de 100644 --- a/roles/router/tasks/main.yaml +++ b/roles/router/tasks/main.yaml @@ -185,7 +185,7 @@ - name: Set Bash as the login shell user: - name: '{{ ansible_env["DOAS_USER"] }}' + name: '{{ ansible_facts.env["DOAS_USER"] }}' shell: /usr/local/bin/bash tags: - bash diff --git a/roles/wap/tasks/main.yaml b/roles/wap/tasks/main.yaml index 5125fd4..244d3f7 100644 --- a/roles/wap/tasks/main.yaml +++ b/roles/wap/tasks/main.yaml @@ -2,8 +2,8 @@ - name: Validate assertions ansible.builtin.assert: that: - - ansible_distribution == "OpenWrt" - - ansible_distribution_major_version == "19" + - ansible_facts.distribution == "OpenWrt" + - ansible_facts.distribution_major_version == "19" - name: Install packages loop: @@ -45,7 +45,8 @@ delegate_to: localhost community.crypto.openssl_privatekey: mode: 0o0444 - path: &local_private_key '{{ playbook_dir }}/{{ ansible_hostname }}.key' + path: &local_private_key |- + '{{ playbook_dir }}/{{ ansible_facts.hostname }}.key' size: 4096 state: present type: RSA @@ -53,7 +54,8 @@ - name: Generate a self-signed SSL certificate locally delegate_to: localhost community.crypto.x509_certificate: - path: &local_public_key '{{ playbook_dir }}/{{ ansible_hostname }}.crt' + path: &local_public_key |- + '{{ playbook_dir }}/{{ ansible_facts.hostname }}.crt' privatekey_path: *local_private_key provider: selfsigned state: present diff --git a/roles/wap/templates/daily.j2 b/roles/wap/templates/daily.j2 index a0e3cfb..6855930 100644 --- a/roles/wap/templates/daily.j2 +++ b/roles/wap/templates/daily.j2 @@ -4,4 +4,5 @@ set -eu opkg update opkg list-upgradable | awk '{print $1}' | sort | xargs -rn1 opkg upgrade --download-only -[ -z "$(opkg list-upgradable)" ] || curl https://notify.shore.co.il/send?message={{ (ansible_facts["hostname"] + " has pending updates.") | urlencode }} +[ -z "$(opkg list-upgradable)" ] || + curl https://notify.shore.co.il/send?message={{ (ansible_facts.hostname + " has pending updates.") | urlencode }} diff --git a/tasks/renew-cert.yaml b/tasks/renew-cert.yaml index bb703ea..3f69a38 100644 --- a/tasks/renew-cert.yaml +++ b/tasks/renew-cert.yaml @@ -23,7 +23,7 @@ community.crypto.openssl_privatekey: # yamllint disable rule:line-length force: |- - {{ account_key_stat.stat.exists and (ansible_date_time.epoch|int - account_key_stat.stat.mtime|int)/(60*60*24*365) >= 4 }} + {{ account_key_stat.stat.exists and (ansible_facts.date_time.epoch|int - account_key_stat.stat.mtime|int)/(60*60*24*365) >= 4 }} # yamllint enable rule:line-length mode: 0o0600 path: *account_key_src @@ -61,7 +61,7 @@ community.crypto.openssl_privatekey: # yamllint disable rule:line-length force: |- - {{ host_key_stat.stat.exists and (ansible_date_time.epoch|int - host_key_stat.stat.mtime|int)/(60*60*24*365) >= 4 }} + {{ host_key_stat.stat.exists and (ansible_facts.date_time.epoch|int - host_key_stat.stat.mtime|int)/(60*60*24*365) >= 4 }} # yamllint enable rule:line-length mode: &mode 0o0600 path: *key_src @@ -179,7 +179,7 @@ community.crypto.openssl_dhparam: # yamllint disable rule:line-length force: |- - {{ dhparams_stat.stat.exists and (ansible_date_time.epoch|int - dhparams_stat.stat.mtime|int)/(60*60*24*7) >= 4 }} + {{ dhparams_stat.stat.exists and (ansible_facts.date_time.epoch|int - dhparams_stat.stat.mtime|int)/(60*60*24*7) >= 4 }} # yamllint enable rule:line-length mode: 0o0644 path: *dhparams diff --git a/update.yaml b/update.yaml index 99c9032..8ebf8f2 100644 --- a/update.yaml +++ b/update.yaml @@ -7,7 +7,7 @@ - update tasks: - name: Update Debian-based hosts - when: ansible_pkg_mgr == 'apt' + when: ansible_facts.pkg_mgr == 'apt' tags: - debian block: @@ -63,7 +63,7 @@ flatpak_update is changed }} - name: Update OpenWRT hosts - when: ansible_pkg_mgr == 'opkg' + when: ansible_facts.pkg_mgr == 'opkg' tags: - openwrt block: @@ -87,7 +87,7 @@ reboot_needed: "{{ opkg_upgrade is changed }}" - name: Update OpenBSD hosts - when: ansible_pkg_mgr == 'openbsd_pkg' + when: ansible_facts.pkg_mgr == 'openbsd_pkg' tags: - openbsd block: -- GitLab