[TIDY] move when statements, fix whitespace

Having the when condition of a task at the top instead of bottom is
easiert to read. Also some spaces were another whitespace character on
accident.
This commit is contained in:
Jannik Beyerstedt 2022-02-13 20:52:02 +01:00
parent 1de4e4ef24
commit a0ac0a67a7
13 changed files with 54 additions and 60 deletions

View file

@ -10,4 +10,4 @@ telegraf_docker_file: "telegraf-docker.conf"
telegraf_unifi_file: "telegraf-UniFi.conf.j2" telegraf_unifi_file: "telegraf-UniFi.conf.j2"
telegraf_airmax_file: "telegraf-AirMAX.conf.j2" telegraf_airmax_file: "telegraf-AirMAX.conf.j2"
exim_etc_mailname: "{{ inventory_hostname }}" exim_etc_mailname: "{{ inventory_hostname }}"

View file

@ -8,21 +8,26 @@
# For Debian Stretch, use a newer package version from backports # For Debian Stretch, use a newer package version from backports
- name: borgbackup - Add debian repo key - name: borgbackup - Add debian repo key
when:
- ansible_distribution_release == 'stretch'
become: yes become: yes
ansible.builtin.apt_key: ansible.builtin.apt_key:
keyserver: pgpkeys.mit.edu keyserver: pgpkeys.mit.edu
id: 8B48AD6246925553 id: 8B48AD6246925553
state: present state: present
- name: borgbackup - Add stretch-backports
when: when:
- ansible_distribution_release == 'stretch' - ansible_distribution_release == 'stretch'
- name: borgbackup - Add stretch-backports
become: yes become: yes
ansible.builtin.apt_repository: ansible.builtin.apt_repository:
repo: deb http://ftp.debian.org/debian stretch-backports main repo: deb http://ftp.debian.org/debian stretch-backports main
state: present state: present
when:
- ansible_distribution_release == 'stretch'
- name: borgbackup - Install borgbackup from stretch-backports - name: borgbackup - Install borgbackup from stretch-backports
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
- ansible_distribution_release == 'stretch'
become: yes become: yes
ansible.builtin.apt: ansible.builtin.apt:
name: borgbackup name: borgbackup
@ -30,8 +35,3 @@
default_release: stretch-backports default_release: stretch-backports
update_cache: yes update_cache: yes
cache_valid_time: 3600 cache_valid_time: 3600
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
- ansible_distribution_release == 'stretch'

View file

@ -8,12 +8,12 @@
# For all other Debian versions, simply install borgbackup # For all other Debian versions, simply install borgbackup
- name: borgbackup - Install borgbackup - name: borgbackup - Install borgbackup
become: yes
ansible.builtin.apt:
name: borgbackup
state: present
when: when:
- borgbackup_passphrase is defined - borgbackup_passphrase is defined
- borgbackup_repo is defined - borgbackup_repo is defined
- borgbackup_hostname is defined - borgbackup_hostname is defined
- ansible_distribution_release != 'stretch' - ansible_distribution_release != 'stretch'
become: yes
ansible.builtin.apt:
name: borgbackup
state: present

View file

@ -6,16 +6,18 @@
# - borgbackup_hostname # - borgbackup_hostname
- name: borgbackup - Install - name: borgbackup - Install
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
block:
- name: borgbackup - Install application
ansible.builtin.include_tasks: "{{ item }}" ansible.builtin.include_tasks: "{{ item }}"
with_first_found: with_first_found:
- "borgbackup-{{ ansible_distribution }}.{{ ansible_distribution_release }}.yml" - "borgbackup-{{ ansible_distribution }}.{{ ansible_distribution_release }}.yml"
- "borgbackup-{{ ansible_distribution }}.yml" - "borgbackup-{{ ansible_distribution }}.yml"
- "borgbackup-{{ (override_os_family is defined) | ternary(override_os_family,ansible_os_family) }}.yml" - "borgbackup-{{ (override_os_family is defined) | ternary(override_os_family,ansible_os_family) }}.yml"
ignore_errors: true ignore_errors: true
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
# copy backup script and enable cronjob # copy backup script and enable cronjob
- name: borgbackup - Copy Borgbackup script - name: borgbackup - Copy Borgbackup script
@ -26,10 +28,6 @@
owner: "{{ ansible_user_id }}" owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}" group: "{{ ansible_user_id }}"
mode: 0775 mode: 0775
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
- name: borgbackup - Run Borgbackup script at 1:00 daily - name: borgbackup - Run Borgbackup script at 1:00 daily
become: yes become: yes
ansible.builtin.cron: ansible.builtin.cron:
@ -37,13 +35,10 @@
minute: "0" minute: "0"
hour: "1" hour: "1"
job: "/usr/local/bin/borgbackup.sh" job: "/usr/local/bin/borgbackup.sh"
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
# safeguard, if the host variables were removed # safeguard, if the host variables were removed
- name: borgbackup - Uninstall - name: borgbackup - Uninstall
when: (borgbackup_passphrase is not defined) or (borgbackup_repo is not defined) or (borgbackup_hostname is not defined)
block: block:
- name: borgbackup - Remove Borgbackup script if no borgbackup config - name: borgbackup - Remove Borgbackup script if no borgbackup config
become: yes become: yes
@ -58,4 +53,3 @@
hour: "1" hour: "1"
job: "/usr/local/bin/borgbackup.sh" job: "/usr/local/bin/borgbackup.sh"
state: absent state: absent
when: (borgbackup_passphrase is not defined) or (borgbackup_repo is not defined) or (borgbackup_hostname is not defined)

View file

@ -14,6 +14,7 @@
register: caddy_releases_cache register: caddy_releases_cache
- name: caddyserver - Install or update - name: caddyserver - Install or update
when: caddy_releases_cache.changed
block: block:
- name: caddyserver - Make temp download directory - name: caddyserver - Make temp download directory
ansible.builtin.file: ansible.builtin.file:
@ -21,6 +22,7 @@
state: directory state: directory
- name: caddyserver - Download caddy webserver (amd64) - name: caddyserver - Download caddy webserver (amd64)
when: ansible_architecture == "x86_64"
become: yes become: yes
ansible.builtin.get_url: ansible.builtin.get_url:
url: "https://caddyserver.com/api/download?os=linux&arch=amd64" url: "https://caddyserver.com/api/download?os=linux&arch=amd64"
@ -28,8 +30,8 @@
group: root group: root
owner: root owner: root
mode: 0755 mode: 0755
when: ansible_architecture == "x86_64"
- name: caddyserver - Download caddy webserver (armv7/ raspberry pi) - name: caddyserver - Download caddy webserver (armv7/ raspberry pi)
when: ansible_architecture == "armv7l"
become: yes become: yes
ansible.builtin.get_url: ansible.builtin.get_url:
url: "https://caddyserver.com/api/download?os=linux&arch=arm&arm=7" url: "https://caddyserver.com/api/download?os=linux&arch=arm&arm=7"
@ -37,8 +39,8 @@
group: root group: root
owner: root owner: root
mode: 0755 mode: 0755
when: ansible_architecture == "armv7l"
- name: caddyserver - Download caddy webserver (arm64) - name: caddyserver - Download caddy webserver (arm64)
when: ansible_architecture == "aarch64"
become: yes become: yes
ansible.builtin.get_url: ansible.builtin.get_url:
url: "https://caddyserver.com/api/download?os=linux&arch=arm64" url: "https://caddyserver.com/api/download?os=linux&arch=arm64"
@ -46,7 +48,6 @@
group: root group: root
owner: root owner: root
mode: 0755 mode: 0755
when: ansible_architecture == "aarch64"
- name: caddyserver - Stop caddy - name: caddyserver - Stop caddy
become: yes become: yes
@ -63,4 +64,3 @@
ansible.builtin.file: ansible.builtin.file:
path: "{{ caddy_cachedir }}/tmp" path: "{{ caddy_cachedir }}/tmp"
state: absent state: absent
when: caddy_releases_cache.changed

View file

@ -6,5 +6,5 @@
ansible.builtin.include_tasks: "caddy-install.yml" ansible.builtin.include_tasks: "caddy-install.yml"
- name: caddyserver - Setup caddy server - name: caddyserver - Setup caddy server
ansible.builtin.include_tasks: "caddy-setup.yml"
when: caddy_email is defined when: caddy_email is defined
ansible.builtin.include_tasks: "caddy-setup.yml"

View file

@ -31,9 +31,9 @@
# # dest: /etc/exim/update-exim.conf.conf # # dest: /etc/exim/update-exim.conf.conf
# # register: cronmails_conffile_update # # register: cronmails_conffile_update
# # - name: cronmails - Run update-exim.conf # # - name: cronmails - Run update-exim.conf
# # when: cronmails_conftmp_update.changed or cronmails_conffile_update.changed
# # become: yes # # become: yes
# # ansible.builtin.shell: "update-exim.conf" # # ansible.builtin.shell: "update-exim.conf"
# # when: cronmails_conftmp_update.changed or cronmails_conffile_update.changed
# - name: cronmails - Enable and start exim # - name: cronmails - Enable and start exim
# become: yes # become: yes
# ansible.builtin.service: # ansible.builtin.service:

View file

@ -37,9 +37,9 @@
content: "{{ exim_etc_mailname }}" content: "{{ exim_etc_mailname }}"
register: cronmails_mailname_update register: cronmails_mailname_update
- name: cronmails - Run update-exim4.conf - name: cronmails - Run update-exim4.conf
when: cronmails_conftmp_update.changed or cronmails_conffile_update.changed or cronmails_mailname_update.changed
become: yes become: yes
ansible.builtin.shell: "update-exim4.conf" ansible.builtin.shell: "update-exim4.conf"
when: cronmails_conftmp_update.changed or cronmails_conffile_update.changed or cronmails_mailname_update.changed
- name: cronmails - Enable and start exim4 - name: cronmails - Enable and start exim4
become: yes become: yes
ansible.builtin.service: ansible.builtin.service:

View file

@ -29,17 +29,17 @@
# IMPORTANT: raspbian needs deb [arch=armhf] https://download.docker.com/linux/raspbian ... # IMPORTANT: raspbian needs deb [arch=armhf] https://download.docker.com/linux/raspbian ...
- name: docker - Add docker CE repo (Debian) - name: docker - Add docker CE repo (Debian)
when: ansible_facts['lsb']['id'] != "Raspbian"
become: yes become: yes
ansible.builtin.apt_repository: ansible.builtin.apt_repository:
repo: "deb [arch={{ dpkg_arch.stdout }}] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable" repo: "deb [arch={{ dpkg_arch.stdout }}] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
state: present state: present
when: ansible_facts['lsb']['id'] != "Raspbian"
- name: docker - Add docker CE repo (Raspbian) - name: docker - Add docker CE repo (Raspbian)
when: ansible_facts['lsb']['id'] == "Raspbian"
become: yes become: yes
ansible.builtin.apt_repository: ansible.builtin.apt_repository:
repo: "deb [arch={{ dpkg_arch.stdout }}] https://download.docker.com/linux/raspbian {{ ansible_distribution_release }} stable" repo: "deb [arch={{ dpkg_arch.stdout }}] https://download.docker.com/linux/raspbian {{ ansible_distribution_release }} stable"
state: present state: present
when: ansible_facts['lsb']['id'] == "Raspbian"
- name: docker - Install docker CE - name: docker - Install docker CE
become: yes become: yes

View file

@ -6,7 +6,7 @@
ansible.builtin.yum_repository: ansible.builtin.yum_repository:
name: influxdb name: influxdb
description: InfluxDB Repository description: InfluxDB Repository
baseurl: https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable baseurl: https://repos.influxdata.com/rhel/7/\$basearch/stable
enabled: yes enabled: yes
gpgcheck: yes gpgcheck: yes
gpgkey: https://repos.influxdata.com/influxdb.key gpgkey: https://repos.influxdata.com/influxdb.key

View file

@ -26,6 +26,7 @@
# Install SNMP utilities for telegraf monitoring # Install SNMP utilities for telegraf monitoring
- name: telegraf - Install SNMP utilities - name: telegraf - Install SNMP utilities
when: telegraf_ubnt_ns_ips is defined
become: yes become: yes
ansible.builtin.apt: ansible.builtin.apt:
name: "{{ packages }}" name: "{{ packages }}"
@ -34,4 +35,3 @@
packages: packages:
- snmp - snmp
- snmp-mibs-downloader - snmp-mibs-downloader
when: telegraf_ubnt_ns_ips is defined

View file

@ -9,6 +9,7 @@
# # Install SNMP utilities for telegraf monitoring # # Install SNMP utilities for telegraf monitoring
# - name: telegraf - Install SNMP utilities # - name: telegraf - Install SNMP utilities
# when: telegraf_ubnt_ns_ips is defined
# become: yes # become: yes
# ansible.builtin.package: # ansible.builtin.package:
# name: "{{ packages }}" # name: "{{ packages }}"
@ -17,9 +18,9 @@
# packages: # packages:
# - snmp # - snmp
# - snmp-mibs-downloader # - snmp-mibs-downloader
# when: telegraf_ubnt_ns_ips is defined
- name: telegraf - Install SNMP utilities - name: telegraf - Install SNMP utilities
when: telegraf_ubnt_ns_ips is defined
become: yes become: yes
ansible.builtin.package: ansible.builtin.package:
name: "{{ packages }}" name: "{{ packages }}"
@ -28,4 +29,3 @@
packages: packages:
- snmp - snmp
- snmp-mibs-downloader - snmp-mibs-downloader
when: telegraf_ubnt_ns_ips is defined

View file

@ -11,6 +11,7 @@
# Install SNMP MIBs # Install SNMP MIBs
- name: telegraf - Install SNMP MIBs - name: telegraf - Install SNMP MIBs
when: telegraf_ubnt_ns_ips is defined
become: yes become: yes
block: block:
- name: SNMP - Download and install Ubiquiti MIB - name: SNMP - Download and install Ubiquiti MIB
@ -30,22 +31,21 @@
name: /etc/snmp/snmp.conf name: /etc/snmp/snmp.conf
line: mibs +ALL line: mibs +ALL
create: yes create: yes
when: telegraf_ubnt_ns_ips is defined
# Configure # Configure
- name: telegraf - Copy telegraf config (Linux) - name: telegraf - Copy telegraf config (Linux)
when: (override_os_family is defined) | ternary(override_os_family,ansible_os_family) != "FreeBSD"
become: yes become: yes
ansible.builtin.template: ansible.builtin.template:
src: "{{ role_path }}/templates/telegraf.conf.j2" src: "{{ role_path }}/templates/telegraf.conf.j2"
dest: /etc/telegraf/telegraf.conf dest: /etc/telegraf/telegraf.conf
when: (override_os_family is defined) | ternary(override_os_family,ansible_os_family) != "FreeBSD"
- name: telegraf - Copy telegraf config (FreeBSD) - name: telegraf - Copy telegraf config (FreeBSD)
when: (override_os_family is defined) | ternary(override_os_family,ansible_os_family) == "FreeBSD"
become: yes become: yes
ansible.builtin.template: ansible.builtin.template:
src: "{{ role_path }}/templates/telegraf.conf.j2" src: "{{ role_path }}/templates/telegraf.conf.j2"
dest: /usr/local/etc/telegraf.conf dest: /usr/local/etc/telegraf.conf
when: (override_os_family is defined) | ternary(override_os_family,ansible_os_family) == "FreeBSD"
- name: telegraf - Enable and restart telegraf - name: telegraf - Enable and restart telegraf
become: yes become: yes