Skip to content

Commit

Permalink
Remove all remaining occurences of (is defined|is_not_defined) vs def…
Browse files Browse the repository at this point in the history
…aulting to sane value

Some inventory booleans were still being tested for "is defined" or
"is not defined" instead of actually testing their value (and
defaulting to a sane value).  All remainders seem to have been
converted now (not tested).

monitor_nut removed rather than converted since hasn't been used for a
long time
  • Loading branch information
spacelama committed Oct 19, 2024
1 parent b4fe1d0 commit b420de7
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 28 deletions.
6 changes: 3 additions & 3 deletions roles/common/tasks/add_boot_flag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
register: systemdboot_cmdline

- name: "Substitute flag {{ grub_setflag }} systemdboot config if already exists but needs updating"
when: (systemdboot_cmdline.stat.exists) and (recovery_systemdboot is not defined)
when: (systemdboot_cmdline.stat.exists) and not (recovery_systemdboot | default(false))
lineinfile:
dest: /etc/kernel/cmdline
backrefs: yes
Expand All @@ -34,7 +34,7 @@
notify: "Regenerate boot config"

- name: "Search for {{ grub_setflag }} in systemdboot config"
when: (systemdboot_cmdline.stat.exists) and (recovery_systemdboot is not defined)
when: (systemdboot_cmdline.stat.exists) and not (recovery_systemdboot | default(false))
register: systemdboot_variable_line_exists
check_mode: yes # cause this to become just a test. If there's already
# relevant settings, then this will think line is
Expand All @@ -60,7 +60,7 @@
changed_when: false

- name: "Append flag {{ grub_setflag }} systemdboot config"
when: (systemdboot_cmdline.stat.exists) and (recovery_systemdboot is not defined) and (systemdboot_variable_line_exists.msg == "line added")
when: (systemdboot_cmdline.stat.exists) and not (recovery_systemdboot | default(false)) and (systemdboot_variable_line_exists.msg == "line added")
lineinfile:
dest: /etc/kernel/cmdline
backrefs: yes
Expand Down
2 changes: 1 addition & 1 deletion roles/common/tasks/remove_boot_flag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
register: systemdboot_cmdline

- name: "Remove {{ grub_setflag_re }} from systemdboot config"
when: (systemdboot_cmdline.stat.exists) and (recovery_systemdboot is not defined)
when: (systemdboot_cmdline.stat.exists) and not (recovery_systemdboot | default(false))
lineinfile:
dest: /etc/kernel/cmdline
backrefs: yes
Expand Down
4 changes: 2 additions & 2 deletions roles/common/vars/calculate_flag_variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@
# about it on the internet, so set this variable in the same way as
# above... except that the same warning gets emitted anyway (haven't
# noticed it cause any harm yet)...
grub_variable: "{{ 'GRUB_CMDLINE_LINUX' if recovery_systemdboot is defined else 'GRUB_CMDLINE_LINUX_DEFAULT' }}"
grub_file_ext: "{{ '-recovery' if recovery_systemdboot is defined else '' }}"
grub_variable: "{{ 'GRUB_CMDLINE_LINUX' if (recovery_systemdboot | default(false)) else 'GRUB_CMDLINE_LINUX_DEFAULT' }}"
grub_file_ext: "{{ '-recovery' if (recovery_systemdboot | default(false)) else '' }}"
2 changes: 1 addition & 1 deletion roles/essentials/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@
state: present
install_recommends: no
become: true
when: mount_ceph_clients is defined
when: mount_ceph_clients | default(false)

- name: remove custom host specific files
file:
Expand Down
2 changes: 1 addition & 1 deletion roles/monitoring/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,4 @@
content: "[Service]\n# https://serverfault.com/questions/1006514/systemd-timer-for-unattended-upgrades ExecStart for some stupid reason are cumulative, so should be reset:\nExecStart=\nExecStart=/usr/share/munin/munin-asyncd --fork\n"
become: true
notify: restart munin-async
when: munin_no_fork is not defined
when: not (munin_no_fork | default(false))
10 changes: 5 additions & 5 deletions roles/openwrt/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
regexp: '^#*enable-reflector='
line: 'enable-reflector=yes'
insertafter: '^#enable-relfector='
when: openwrt_router_packages is defined
when: openwrt_router_packages | default(false)

# https://openwrt.org/docs/guide-user/network/wifi/usteer talks
# about needing wpad full (wpad-wolfssl or wpad-openssl), but we
Expand All @@ -117,7 +117,7 @@
opkg:
name: tcpdump,strace,lsof,usbutils,ethtool,psmisc,procps-ng-ps,procps-ng-watch,procps-ng-vmstat,iftop,htop,btop,less,diffutils,perl,perlbase-tie # perlbase-tie for munin sensors_
state: present
when: openwrt_heavy_installation is defined
when: openwrt_heavy_installation | default(true)

- name: install host specific packages
opkg:
Expand All @@ -130,7 +130,7 @@
opkg:
name: luci-app-nut,nut,nut-upscmd,nut-upsc,nut-upslog,nut-server,nut-driver-blazer_usb,nut-driver-usbhid-ups,nut-upssched,nut-avahi-service,nut-upsrw,nut-web-cgi
state: present
when: nut_install is defined
when: nut_install | default(false)

- name: install nut munin plugins
file:
Expand All @@ -139,7 +139,7 @@
state: link
force: yes
with_items: [ charge,voltages,freq,current ]
when: nut_install is defined
when: nut_install | default(false)

- name: install temperature sensors munin plugin
file:
Expand Down Expand Up @@ -224,7 +224,7 @@

- name: include uci config
include_tasks: uci_config.yml
when: run_uci_config is defined
when: run_uci_config | default(false)

- name: commit changes
meta: flush_handlers
Expand Down
6 changes: 3 additions & 3 deletions roles/openwrt/tasks/uci_network_interface_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
loop_var: uci_command
with_items:
- "uci add network device ; uci set network.@device[-1].type='bridge' ; uci set network.@device[-1].name='br-{{ interface.key }}' ; uci add_list network.@device[-1].ports='{{ switch_interface | default('eth0') }}.{{ interface.value }}0'"
when: openwrt_dsa_switch_config is not defined
when: not (openwrt_dsa_switch_config | default(false))

# just adding the interface manually without creating a vlan first yields this in luci:
# uci set network.LANWINDOWS7=interface
Expand Down Expand Up @@ -70,7 +70,7 @@
value:
device: "br-{{ interface.key }}"
notify: uci commit
when: openwrt_dsa_switch_config is not defined
when: not (openwrt_dsa_switch_config | default(false))

- name: set interface for {{ interface.key }} to br0.{{ interface.value }}0
uci:
Expand All @@ -79,7 +79,7 @@
value:
device: "br0.{{ interface.value }}0"
notify: uci commit
when: openwrt_dsa_switch_config is defined
when: openwrt_dsa_switch_config | default(false)

- name: try setting option to interface {{ interface.key }}
uci:
Expand Down
4 changes: 2 additions & 2 deletions roles/pve_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@
content: "# ANSIBLE CONTROLLED\n# https://forum.proxmox.com/threads/how-to-disable-fencing-for-debugging.59625/\noptions softdog soft_noboot=1\n"
dest: "/etc/modprobe.d/softdog.conf"
become: true
when: no_softdog_reboot is defined
when: no_softdog_reboot | default(false)

- name: include after bootstrap tasks
include_tasks: after_bootstrap.yml
when: in_bootstrap is not defined
when: not (in_bootstrap | default(false))

# FIXME: install QemuServer hook to call the guest hook
4 changes: 2 additions & 2 deletions roles/smtp/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@
modification_time: preserve
access_time: preserve
become: true
when: (host_is_mda | default(false)) and (dovecot_insecure_logfile_creation is defined)
when: (host_is_mda | default(false)) and (dovecot_insecure_logfile_creation | default(false))

- name: Rotate imap-via-ssh logfile
copy:
src: etc/logrotate.d/dovecot-custom
dest: /etc/logrotate.d/dovecot-custom
become: true
when: (host_is_mda | default(false)) and (dovecot_insecure_logfile_creation is defined)
when: (host_is_mda | default(false)) and (dovecot_insecure_logfile_creation | default(false))

- name: Install dovecot/mail.conf
copy:
Expand Down
4 changes: 2 additions & 2 deletions roles/smtp/tasks/postfix-debconf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
value: "[smtp.gmail.com]:587"
become: true
notify: reconfigure postfix
when: smtp_relay_to_gmail is defined and host_is_smtp_relay | default(false)
when: (smtp_relay_to_gmail | default(false)) and (host_is_smtp_relay | default(false))

- name: Set relayhost
debconf:
Expand All @@ -97,7 +97,7 @@
value: "{{ smtp_server }}"
become: true
notify: reconfigure postfix
when: not (smtp_relay_to_gmail is defined and host_is_smtp_relay | default(false))
when: not ((smtp_relay_to_gmail | default(false)) and (host_is_smtp_relay | default(false)))

- name: Set mynetworks
debconf:
Expand Down
2 changes: 1 addition & 1 deletion templates/etc/auto.nas.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#}

{# FIXME: might need wsize and rsize to not run out memory with mount/umount cycles: https://www.spinics.net/lists/ceph-users/msg60621.html #}
{% if mount_ceph_clients is defined %}
{% if mount_ceph_clients | default(false) %}
{% for mount in ceph_client_mounts %}
{{ mount.mount }} -fstype=ceph,name={{ mount.name }},mds_namespace={{ mount.mds_namespace }},{{ mount.options }} {{ mount.mons }}:{{ mount.remote_path }}
{% endfor %}
Expand Down
3 changes: 0 additions & 3 deletions templates/var_spool_cron/root.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ MAILTO=tconnors
{% if inventory_hostname is regex('^pve.$') %}
@reboot if hostname | grep -q ^pve ; then echo schedutil | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; fi
{% endif %}
{% if monitor_nut is defined %}
* * * * * /root/bin/restart-nut-driver
{% endif %}
{% if not (host_is_container | default(false)) %}
00 4 * * * /usr/local/bin/checkntp
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions vars/tasmota.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
no_syslog_setting: []

# this always gets marked as Changed, so don't run it by default
psk_setting_enabled: "{{ setpsk is defined | ternary(psk_setting, no_psk_setting) }}"
psk_setting_enabled: "{{ setpsk | default(false) | ternary(psk_setting, no_psk_setting) }}"
# this always gets marked as Changed, so don't run it by default
syslog_setting_enabled: "{{ setsyslog is defined | ternary(syslog_setting, no_syslog_setting) }}"
syslog_setting_enabled: "{{ setsyslog | default(false) | ternary(syslog_setting, no_syslog_setting) }}"

compulsory_tasmota_commands:
- command: LogHost
Expand Down

0 comments on commit b420de7

Please sign in to comment.