[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_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
- name: borgbackup - Add debian repo key
when:
- ansible_distribution_release == 'stretch'
become: yes
ansible.builtin.apt_key:
keyserver: pgpkeys.mit.edu
id: 8B48AD6246925553
state: present
- name: borgbackup - Add stretch-backports
when:
- ansible_distribution_release == 'stretch'
- name: borgbackup - Add stretch-backports
become: yes
ansible.builtin.apt_repository:
repo: deb http://ftp.debian.org/debian stretch-backports main
state: present
when:
- ansible_distribution_release == 'stretch'
- 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
ansible.builtin.apt:
name: borgbackup
@ -30,8 +35,3 @@
default_release: stretch-backports
update_cache: yes
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
- name: borgbackup - Install borgbackup
become: yes
ansible.builtin.apt:
name: borgbackup
state: present
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
- ansible_distribution_release != 'stretch'
become: yes
ansible.builtin.apt:
name: borgbackup
state: present

View file

@ -6,44 +6,39 @@
# - borgbackup_hostname
- name: borgbackup - Install
ansible.builtin.include_tasks: "{{ item }}"
with_first_found:
- "borgbackup-{{ ansible_distribution }}.{{ ansible_distribution_release }}.yml"
- "borgbackup-{{ ansible_distribution }}.yml"
- "borgbackup-{{ (override_os_family is defined) | ternary(override_os_family,ansible_os_family) }}.yml"
ignore_errors: true
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
block:
- name: borgbackup - Install application
ansible.builtin.include_tasks: "{{ item }}"
with_first_found:
- "borgbackup-{{ ansible_distribution }}.{{ ansible_distribution_release }}.yml"
- "borgbackup-{{ ansible_distribution }}.yml"
- "borgbackup-{{ (override_os_family is defined) | ternary(override_os_family,ansible_os_family) }}.yml"
ignore_errors: true
# copy backup script and enable cronjob
- name: borgbackup - Copy Borgbackup script
become: yes
ansible.builtin.template:
src: "{{ role_path }}/templates/borgbackup.sh"
dest: /usr/local/bin/borgbackup.sh
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"
mode: 0775
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
- name: borgbackup - Run Borgbackup script at 1:00 daily
become: yes
ansible.builtin.cron:
name: "Create Backup"
minute: "0"
hour: "1"
job: "/usr/local/bin/borgbackup.sh"
when:
- borgbackup_passphrase is defined
- borgbackup_repo is defined
- borgbackup_hostname is defined
# copy backup script and enable cronjob
- name: borgbackup - Copy Borgbackup script
become: yes
ansible.builtin.template:
src: "{{ role_path }}/templates/borgbackup.sh"
dest: /usr/local/bin/borgbackup.sh
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"
mode: 0775
- name: borgbackup - Run Borgbackup script at 1:00 daily
become: yes
ansible.builtin.cron:
name: "Create Backup"
minute: "0"
hour: "1"
job: "/usr/local/bin/borgbackup.sh"
# safeguard, if the host variables were removed
- name: borgbackup - Uninstall
when: (borgbackup_passphrase is not defined) or (borgbackup_repo is not defined) or (borgbackup_hostname is not defined)
block:
- name: borgbackup - Remove Borgbackup script if no borgbackup config
become: yes
@ -58,4 +53,3 @@
hour: "1"
job: "/usr/local/bin/borgbackup.sh"
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
- name: caddyserver - Install or update
when: caddy_releases_cache.changed
block:
- name: caddyserver - Make temp download directory
ansible.builtin.file:
@ -21,6 +22,7 @@
state: directory
- name: caddyserver - Download caddy webserver (amd64)
when: ansible_architecture == "x86_64"
become: yes
ansible.builtin.get_url:
url: "https://caddyserver.com/api/download?os=linux&arch=amd64"
@ -28,8 +30,8 @@
group: root
owner: root
mode: 0755
when: ansible_architecture == "x86_64"
- name: caddyserver - Download caddy webserver (armv7/ raspberry pi)
when: ansible_architecture == "armv7l"
become: yes
ansible.builtin.get_url:
url: "https://caddyserver.com/api/download?os=linux&arch=arm&arm=7"
@ -37,8 +39,8 @@
group: root
owner: root
mode: 0755
when: ansible_architecture == "armv7l"
- name: caddyserver - Download caddy webserver (arm64)
when: ansible_architecture == "aarch64"
become: yes
ansible.builtin.get_url:
url: "https://caddyserver.com/api/download?os=linux&arch=arm64"
@ -46,7 +48,6 @@
group: root
owner: root
mode: 0755
when: ansible_architecture == "aarch64"
- name: caddyserver - Stop caddy
become: yes
@ -63,4 +64,3 @@
ansible.builtin.file:
path: "{{ caddy_cachedir }}/tmp"
state: absent
when: caddy_releases_cache.changed

View file

@ -6,5 +6,5 @@
ansible.builtin.include_tasks: "caddy-install.yml"
- name: caddyserver - Setup caddy server
ansible.builtin.include_tasks: "caddy-setup.yml"
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
# # register: cronmails_conffile_update
# # - name: cronmails - Run update-exim.conf
# # when: cronmails_conftmp_update.changed or cronmails_conffile_update.changed
# # become: yes
# # ansible.builtin.shell: "update-exim.conf"
# # when: cronmails_conftmp_update.changed or cronmails_conffile_update.changed
# - name: cronmails - Enable and start exim
# become: yes
# ansible.builtin.service:

View file

@ -37,9 +37,9 @@
content: "{{ exim_etc_mailname }}"
register: cronmails_mailname_update
- name: cronmails - Run update-exim4.conf
when: cronmails_conftmp_update.changed or cronmails_conffile_update.changed or cronmails_mailname_update.changed
become: yes
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
become: yes
ansible.builtin.service:

View file

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

View file

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

View file

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

View file

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

View file

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