diff --git a/tasks/apk/packages.yaml b/tasks/apk/packages.yaml index f6d5e2d..967b26f 100644 --- a/tasks/apk/packages.yaml +++ b/tasks/apk/packages.yaml @@ -2,7 +2,7 @@ # manage packages - name: "manage packages" - when: 'ansible_os_family == "Alpine"' + when: 'ansible_facts["os_family"] == "Alpine"' become: true block: @@ -29,7 +29,7 @@ community.general.apk: name: "qemu-guest-agent" state: "absent" - when: "ansible_virtualization_type == 'lxc'" + when: "ansible_facts['virtualization_type'] == 'lxc'" # install qemu-guest-agent @@ -37,7 +37,7 @@ community.general.apk: name: "qemu-guest-agent" state: "present" - when: "ansible_virtualization_type == 'kvm'" + when: "ansible_facts['virtualization_type'] == 'kvm'" # clean cache - name: "clean cache" diff --git a/tasks/apt/cleanup.yaml b/tasks/apt/cleanup.yaml index 1b2a4a0..1985523 100644 --- a/tasks/apt/cleanup.yaml +++ b/tasks/apt/cleanup.yaml @@ -11,11 +11,11 @@ clean: true changed_when: false failed_when: false - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' # run fstrim if target is a VM - name: "fstrim" ansible.builtin.command: "fstrim /" changed_when: false failed_when: false - when: "ansible_virtualization_type == 'kvm'" + when: "ansible_facts['virtualization_type'] == 'kvm'" diff --git a/tasks/apt/config.yaml b/tasks/apt/config.yaml index 12c8226..d8fcf5a 100644 --- a/tasks/apt/config.yaml +++ b/tasks/apt/config.yaml @@ -13,13 +13,13 @@ owner: "root" group: "root" mode: "0644" - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' - name: "apt - config - configure apt unatteded updates" ansible.builtin.template: - src: "templates/apt/conf.d/50unattended-upgrades.{{ ansible_distribution }}.j2" + src: "templates/apt/conf.d/50unattended-upgrades.{{ ansible_facts['distribution'] }}.j2" dest: "/etc/apt/apt.conf.d/50unattended-upgrades" owner: "root" group: "root" mode: "0644" - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' diff --git a/tasks/apt/packages.yaml b/tasks/apt/packages.yaml index 8e45576..720d998 100644 --- a/tasks/apt/packages.yaml +++ b/tasks/apt/packages.yaml @@ -11,7 +11,7 @@ name: "{{ apt_default_install }}" state: "present" update_cache: true - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' loop: "{{ apt_default_packages_install }}" loop_control: loop_var: "apt_default_install" @@ -22,7 +22,7 @@ name: "{{ apt_default_delete }}" state: "absent" purge: true - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' loop: "{{ apt_default_packages_delete }}" loop_control: loop_var: "apt_default_delete" diff --git a/tasks/apt/sources.yaml b/tasks/apt/sources.yaml index fde952b..a0dae9e 100644 --- a/tasks/apt/sources.yaml +++ b/tasks/apt/sources.yaml @@ -8,14 +8,14 @@ # configure legacy apt sources - name: "configure legacy apt sources" when: > - (ansible_distribution == "Debian" and ansible_distribution_major_version | int <= 12) or - (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int <= 23) + (ansible_facts['distribution'] == "Debian" and ansible_facts['distribution_major_version'] | int <= 12) or + (ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] | int <= 23) block: # configure apt sources - name: "apt - config - configure apt sources" ansible.builtin.template: - src: "templates/apt/sources.d/{{ ansible_distribution | lower }}.sources.list.j2" + src: "templates/apt/sources.d/{{ ansible_facts['distribution'] | lower }}.sources.list.j2" dest: "/etc/apt/sources.list" owner: "root" group: "root" @@ -25,15 +25,15 @@ # configure deb822 apt sources - name: "configure deb822 apt sources" when: > - (ansible_distribution == "Debian" and ansible_distribution_major_version | int >= 13) or - (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int >= 24) + (ansible_facts['distribution'] == "Debian" and ansible_facts['distribution_major_version'] | int >= 13) or + (ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] | int >= 24) block: # configure apt sources - name: "apt - config - configure apt sources" ansible.builtin.template: - src: "templates/apt/sources.d/{{ ansible_distribution | lower }}.sources.j2" - dest: "/etc/apt/sources.list.d/{{ ansible_distribution | lower }}.sources" + src: "templates/apt/sources.d/{{ ansible_facts['distribution'] | lower }}.sources.j2" + dest: "/etc/apt/sources.list.d/{{ ansible_facts['distribution'] | lower }}.sources" owner: "root" group: "root" mode: "0644" diff --git a/tasks/apt/update.yaml b/tasks/apt/update.yaml index 94ed44d..324610e 100644 --- a/tasks/apt/update.yaml +++ b/tasks/apt/update.yaml @@ -3,7 +3,7 @@ # apt update - name: "apt update" tags: "apt-update" - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' block: # run apt update @@ -35,7 +35,7 @@ cmd: "fstrim /" changed_when: false failed_when: false - when: "ansible_virtualization_type == 'kvm'" + when: "ansible_facts['virtualization_type'] == 'kvm'" # check for reboots - name: "check if reboot required" diff --git a/tasks/cron.yaml b/tasks/cron.yaml index a7750da..c487133 100644 --- a/tasks/cron.yaml +++ b/tasks/cron.yaml @@ -9,8 +9,8 @@ group: "root" mode: "0644" when: - - "ansible_os_family == 'Debian'" - - "ansible_virtualization_type == 'lxc'" + - "ansible_facts['os_family'] == 'Debian'" + - "ansible_facts['virtualization_type'] == 'lxc'" tags: "cron" # configure cron @@ -21,5 +21,5 @@ owner: "root" group: "root" mode: "0600" - when: 'ansible_os_family == "Alpine"' + when: 'ansible_facts["os_family"] == "Alpine"' tags: "cron" diff --git a/tasks/environment.yaml b/tasks/environment.yaml index 236658e..5c79b07 100644 --- a/tasks/environment.yaml +++ b/tasks/environment.yaml @@ -8,5 +8,5 @@ owner: "root" group: "root" mode: "0644" - when: 'ansible_distribution == "Ubuntu"' + when: 'ansible_facts["distribution"] == "Ubuntu"' tags: "environment-file" diff --git a/tasks/firewall.yaml b/tasks/firewall.yaml index c9230eb..29d07ab 100644 --- a/tasks/firewall.yaml +++ b/tasks/firewall.yaml @@ -13,7 +13,7 @@ # manage firewall for debian - name: "firewall - debian family" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" block: # remove and disable firewall diff --git a/tasks/fstab.yaml b/tasks/fstab.yaml index 5d949b6..6aff4e5 100644 --- a/tasks/fstab.yaml +++ b/tasks/fstab.yaml @@ -11,5 +11,5 @@ dump: "0" passno: "0" when: - - "ansible_os_family == 'Alpine'" + - "ansible_facts['os_family'] == 'Alpine'" - "'router' not in inventory_hostname" diff --git a/tasks/hostname.yaml b/tasks/hostname.yaml index 3e84f9e..697d8f1 100644 --- a/tasks/hostname.yaml +++ b/tasks/hostname.yaml @@ -11,8 +11,8 @@ - name: "manage /etc/hosts file for hostname" ansible.builtin.lineinfile: path: "/etc/hosts" - regexp: '^{{ ansible_default_ipv4.address }}\s+.*{{ inventory_hostname_short }}.*$' - line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }} {{ inventory_hostname_short }}" + regexp: '^{{ ansible_facts["default_ipv4"].address }}\s+.*{{ inventory_hostname_short }}.*$' + line: "{{ ansible_facts['default_ipv4'].address }} {{ inventory_hostname }} {{ inventory_hostname_short }}" backup: true tags: - "hostfile" diff --git a/tasks/journald.yaml b/tasks/journald.yaml index f7ec7aa..ef5704d 100644 --- a/tasks/journald.yaml +++ b/tasks/journald.yaml @@ -8,6 +8,6 @@ owner: "root" group: "root" mode: "0644" - when: 'ansible_distribution == "Ubuntu"' + when: 'ansible_facts["distribution"] == "Ubuntu"' notify: "restart journald" tags: "journald" diff --git a/tasks/lldpd.yaml b/tasks/lldpd.yaml index fcd3a73..baf5bb6 100644 --- a/tasks/lldpd.yaml +++ b/tasks/lldpd.yaml @@ -6,6 +6,6 @@ name: "lldpd" state: "present" cache_valid_time: 3600 - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' notify: "restart lldpd" tags: "lldp" diff --git a/tasks/lxd.yaml b/tasks/lxd.yaml index d4a17d5..ecd5183 100644 --- a/tasks/lxd.yaml +++ b/tasks/lxd.yaml @@ -6,5 +6,5 @@ name: "lxd" state: "absent" purge: true - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' tags: "lxd" diff --git a/tasks/main.yaml b/tasks/main.yaml index 6a74e31..caddf2d 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -8,7 +8,7 @@ # load os variables - name: "include os specific vars" - ansible.builtin.include_vars: "vars/{{ ansible_os_family }}.yaml" + ansible.builtin.include_vars: "vars/{{ ansible_facts['os_family'] }}.yaml" tags: "always" # set dns @@ -19,13 +19,13 @@ # set hostname - name: "set hostname" ansible.builtin.import_tasks: "hostname.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "hostname" # set locale - name: "set locale" ansible.builtin.import_tasks: "locale.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "locale" # environment @@ -47,8 +47,8 @@ - name: "swap" ansible.builtin.import_tasks: "swap.yaml" when: - - "ansible_os_family =='Debian'" - - "ansible_virtualization_type == 'kvm'" + - "ansible_facts['os_family'] =='Debian'" + - "ansible_facts['virtualization_type'] == 'kvm'" tags: "swap" # manage fstab @@ -59,13 +59,13 @@ # apk - name: "apk" ansible.builtin.import_tasks: "apk/packages.yaml" - when: 'ansible_os_family == "Alpine"' + when: 'ansible_facts["os_family"] == "Alpine"' tags: "apk" # apt - name: "apt" ansible.builtin.import_tasks: "apt/sources.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "apt" # flush handler @@ -74,22 +74,22 @@ - name: "apt - update" ansible.builtin.import_tasks: "apt/update.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "apt-update" - name: "apt - packages" ansible.builtin.import_tasks: "apt/packages.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "apt" - name: "apt - config" ansible.builtin.import_tasks: "apt/config.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "apt" - name: "apt - cleanup" ansible.builtin.import_tasks: "apt/cleanup.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "apt-cleanup" # manage profile @@ -100,7 +100,7 @@ # telemetry - name: "telemetry" ansible.builtin.import_tasks: "telemetry.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "telemetry" # service @@ -111,7 +111,7 @@ loop_var: "__service" when: - "service is defined" - - "ansible_os_family == 'Debian'" + - "ansible_facts['os_family'] == 'Debian'" # flush handler - name: "flush handlers" @@ -120,7 +120,7 @@ # chrony - name: "ntp" ansible.builtin.import_tasks: "ntp.yaml" - when: "ansible_virtualization_type in ['kvm', 'none']" + when: "ansible_facts['virtualization_type'] in ['kvm', 'none']" tags: "ntp" # flush handler @@ -130,22 +130,22 @@ # snap - name: "snap - daemon" ansible.builtin.import_tasks: "snap/snap_daemon.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "snap" - name: "snap - package" ansible.builtin.import_tasks: "snap/snap_package.yaml" when: - "snap_package is defined" - - "ansible_os_family == 'Debian'" + - "ansible_facts['os_family'] == 'Debian'" tags: "snap" # lxd - name: "lxd" ansible.builtin.import_tasks: "lxd.yaml" when: - - "ansible_os_family =='Debian'" - - "ansible_virtualization_type == 'kvm'" + - "ansible_facts['os_family'] =='Debian'" + - "ansible_facts['virtualization_type'] == 'kvm'" tags: "lxd" # flush handler @@ -155,7 +155,7 @@ # sysctl - name: "sysctl - set sysctl" ansible.builtin.import_tasks: "sysctl.yaml" - when: "ansible_virtualization_type in ['kvm', 'none']" + when: "ansible_facts['virtualization_type'] in ['kvm', 'none']" tags: "sysctl" # systemctl @@ -165,8 +165,8 @@ loop_control: loop_var: "__systemctl" when: - - "ansible_os_family =='Debian'" - - "ansible_virtualization_type == 'kvm'" + - "ansible_facts['os_family'] =='Debian'" + - "ansible_facts['virtualization_type'] == 'kvm'" tags: "systemctl" # syslog @@ -185,7 +185,7 @@ # journald - name: "journald" ansible.builtin.import_tasks: "journald.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "journald" # flush handler @@ -217,5 +217,5 @@ # firewall - name: "firewall" ansible.builtin.import_tasks: "firewall.yaml" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" tags: "firewall" diff --git a/tasks/motd.yaml b/tasks/motd.yaml index 304863f..e78a6a1 100644 --- a/tasks/motd.yaml +++ b/tasks/motd.yaml @@ -6,7 +6,7 @@ # cleanup old motd debian - name: "cleanup old motd debian" - when: "ansible_os_family == 'Debian'" + when: "ansible_facts['os_family'] == 'Debian'" block: # find old motd files @@ -41,7 +41,7 @@ owner: "root" group: "root" mode: "0755" - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' # configure motd - name: "motd - siempie - alpine" @@ -51,4 +51,4 @@ owner: "root" group: "root" mode: "0755" - when: 'ansible_os_family == "Alpine"' + when: 'ansible_facts["os_family"] == "Alpine"' diff --git a/tasks/ntp.yaml b/tasks/ntp.yaml index 2db20a0..d14fe93 100644 --- a/tasks/ntp.yaml +++ b/tasks/ntp.yaml @@ -10,7 +10,7 @@ name: "chrony" state: "present" update_cache: true - when: 'ansible_os_family == "Alpine"' + when: 'ansible_facts["os_family"] == "Alpine"' # create keys file - name: "ntp - chrony keys file" @@ -21,14 +21,14 @@ mode: "0440" state: "touch" notify: "restart chrony" - when: 'ansible_os_family == "Alpine"' + when: 'ansible_facts["os_family"] == "Alpine"' # install chrony - name: "ntp - install - chrony debian" ansible.builtin.apt: name: "chrony" state: "present" - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' # configure chrony - name: "ntp - config - configure chrony" diff --git a/tasks/profile.yaml b/tasks/profile.yaml index de340e2..b540ed9 100644 --- a/tasks/profile.yaml +++ b/tasks/profile.yaml @@ -7,4 +7,4 @@ line: "export PS1='\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '" create: true mode: "0644" - when: 'ansible_os_family == "Alpine"' + when: 'ansible_facts["os_family"] == "Alpine"' diff --git a/tasks/sshd.yaml b/tasks/sshd.yaml index e6ed0a8..402811d 100644 --- a/tasks/sshd.yaml +++ b/tasks/sshd.yaml @@ -9,7 +9,7 @@ group: "root" mode: "0644" notify: "restart ssh" - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' tags: "sshd" # configure sshd @@ -21,5 +21,5 @@ group: "root" mode: "0644" notify: "restart ssh alpine" - when: 'ansible_os_family == "Alpine"' + when: 'ansible_facts["os_family"] == "Alpine"' tags: "sshd" diff --git a/tasks/syslog/config.yaml b/tasks/syslog/config.yaml index b0a5f7f..33f2850 100644 --- a/tasks/syslog/config.yaml +++ b/tasks/syslog/config.yaml @@ -13,7 +13,7 @@ owner: "root" group: "root" mode: "0644" - when: 'ansible_distribution == "Alpine"' + when: 'ansible_facts["distribution"] == "Alpine"' notify: "restart syslog alpine" # configure rsyslogd - debian @@ -24,7 +24,7 @@ owner: "root" group: "root" mode: "0644" - when: 'ansible_distribution == "Debian"' + when: 'ansible_facts["distribution"] == "Debian"' notify: "restart rsyslog" # configure rsyslogd - ubuntu @@ -35,7 +35,7 @@ owner: "root" group: "root" mode: "0644" - when: 'ansible_distribution == "Ubuntu"' + when: 'ansible_facts["distribution"] == "Ubuntu"' notify: "restart rsyslog" # configure rsyslogd - apt @@ -46,7 +46,7 @@ owner: "root" group: "root" mode: "0644" - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' notify: "restart rsyslog" # configure rsyslogd @@ -57,5 +57,5 @@ owner: "root" group: "root" mode: "0644" - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' notify: "restart rsyslog" diff --git a/tasks/syslog/install.yaml b/tasks/syslog/install.yaml index f61d459..bc2ac70 100644 --- a/tasks/syslog/install.yaml +++ b/tasks/syslog/install.yaml @@ -6,5 +6,5 @@ name: "rsyslog" state: "present" cache_valid_time: 3600 - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' tags: "syslog" diff --git a/tasks/systemctl.yaml b/tasks/systemctl.yaml index 2babc1a..c1c7d10 100644 --- a/tasks/systemctl.yaml +++ b/tasks/systemctl.yaml @@ -8,6 +8,6 @@ owner: "root" group: "root" mode: "0644" - when: 'ansible_os_family == "Debian"' + when: 'ansible_facts["os_family"] == "Debian"' notify: "daemon-reload fstrim.timer" tags: "systemctl" diff --git a/tasks/telemetry.yaml b/tasks/telemetry.yaml index 1441db9..6d12498 100644 --- a/tasks/telemetry.yaml +++ b/tasks/telemetry.yaml @@ -5,5 +5,5 @@ ansible.builtin.file: path: "/etc/cron.daily/popularity-contest" state: "absent" - when: 'ansible_distribution == "Ubuntu"' + when: 'ansible_facts["distribution"] == "Ubuntu"' tags: "telemetry"