From 4d5c390d46c70a3ee035b7584e253de8996fe44f Mon Sep 17 00:00:00 2001 From: WickedYoda <68271168+wickedyoda@users.noreply.github.com> Date: Wed, 21 Oct 2026 12:59:57 -0500 Subject: [PATCH] add playbooks and power shell scripts add playbooks and power shell scripts --- ansible playbooks/Kiosk.yml | 134 ++++++++++++++++++ ansible playbooks/keep_pc_from_sleeping.yml | 12 ++ .../remove_shutdown_start_menu.yml | 22 +++ .../unblock_shutdown_from_start_menu.yml | 49 +++++++ .../windows_updates_and_defender.yml | 37 +++++ ...keep pc from sleeping or shutting down.ps1 | 10 ++ .../remove_shutdown_start-menu.ps1 | 21 +++ .../unblock shutdown from startmenu.ps1 | 28 ++++ .../windows updates and defender.ps1 | 11 ++ 9 files changed, 324 insertions(+) create mode 100644 ansible playbooks/Kiosk.yml create mode 100644 ansible playbooks/keep_pc_from_sleeping.yml create mode 100644 ansible playbooks/remove_shutdown_start_menu.yml create mode 100644 ansible playbooks/unblock_shutdown_from_start_menu.yml create mode 100644 ansible playbooks/windows_updates_and_defender.yml create mode 100644 powershell_scripts/keep pc from sleeping or shutting down.ps1 create mode 100644 powershell_scripts/remove_shutdown_start-menu.ps1 create mode 100644 powershell_scripts/unblock shutdown from startmenu.ps1 create mode 100644 powershell_scripts/windows updates and defender.ps1 diff --git a/ansible playbooks/Kiosk.yml b/ansible playbooks/Kiosk.yml new file mode 100644 index 0000000..b68428e --- /dev/null +++ b/ansible playbooks/Kiosk.yml @@ -0,0 +1,134 @@ +--- +- name: Configure kiosk power behavior and nightly reboot + hosts: all + gather_facts: true + + tasks: + - name: Disable system sleep and hibernation targets + ansible.builtin.systemd_service: + name: "{{ item }}" + state: stopped + masked: true + loop: + - sleep.target + - suspend.target + - hibernate.target + - hybrid-sleep.target + become: true + when: ansible_os_family == 'Debian' + + - name: Configure GNOME to keep the display on and avoid idle sleep + ansible.builtin.copy: + dest: /etc/dconf/db/local.d/90-kiosk-power + owner: root + group: root + mode: '0644' + content: | + [org/gnome/desktop/session] + idle-delay=uint32 0 + + [org/gnome/desktop/screensaver] + idle-activation-enabled=false + + [org/gnome/settings-daemon/plugins/power] + sleep-inactive-ac-type='nothing' + sleep-inactive-ac-timeout=0 + sleep-inactive-battery-type='nothing' + sleep-inactive-battery-timeout=0 + become: true + when: ansible_os_family == 'Debian' + + - name: Lock GNOME kiosk power settings + ansible.builtin.copy: + dest: /etc/dconf/db/local.d/locks/90-kiosk-power + owner: root + group: root + mode: '0644' + content: | + /org/gnome/desktop/session/idle-delay + /org/gnome/desktop/screensaver/idle-activation-enabled + /org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-type + /org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-timeout + /org/gnome/settings-daemon/plugins/power/sleep-inactive-battery-type + /org/gnome/settings-daemon/plugins/power/sleep-inactive-battery-timeout + become: true + when: ansible_os_family == 'Debian' + + - name: Check whether dconf is installed + ansible.builtin.stat: + path: /usr/bin/dconf + register: kiosk_dconf + when: ansible_os_family == 'Debian' + + - name: Apply the GNOME system configuration database + ansible.builtin.command: dconf update + changed_when: true + become: true + when: + - ansible_os_family == 'Debian' + - kiosk_dconf.stat.exists + + - name: Install the nightly reboot service + ansible.builtin.copy: + dest: /etc/systemd/system/kiosk-nightly-reboot.service + owner: root + group: root + mode: '0644' + content: | + [Unit] + Description=Reboot kiosk every night + + [Service] + Type=oneshot + ExecStart=/usr/bin/systemctl reboot + become: true + when: ansible_os_family == 'Debian' + + - name: Install the midnight reboot timer + ansible.builtin.copy: + dest: /etc/systemd/system/kiosk-nightly-reboot.timer + owner: root + group: root + mode: '0644' + content: | + [Unit] + Description=Schedule nightly kiosk reboot + + [Timer] + OnCalendar=*-*-* 00:00:00 + Persistent=true + Unit=kiosk-nightly-reboot.service + + [Install] + WantedBy=timers.target + become: true + when: ansible_os_family == 'Debian' + + - name: Enable the nightly reboot timer + ansible.builtin.systemd_service: + name: kiosk-nightly-reboot.timer + daemon_reload: true + enabled: true + state: started + become: true + when: ansible_os_family == 'Debian' + + - name: Disable Windows automatic sleep and display timeouts + ansible.windows.win_command: "powercfg.exe /change {{ item }} 0" + loop: + - standby-timeout-ac + - standby-timeout-dc + - hibernate-timeout-ac + - hibernate-timeout-dc + - monitor-timeout-ac + - monitor-timeout-dc + changed_when: true + when: ansible_os_family == 'Windows' + + - name: Schedule Windows to reboot every night at midnight + ansible.windows.win_command: >- + schtasks.exe /Create /TN "Kiosk nightly reboot" + /TR "shutdown.exe /r /f /t 0" + /SC DAILY /ST 00:00 /RU SYSTEM /RL HIGHEST /F + changed_when: true + when: ansible_os_family == 'Windows' diff --git a/ansible playbooks/keep_pc_from_sleeping.yml b/ansible playbooks/keep_pc_from_sleeping.yml new file mode 100644 index 0000000..171bed9 --- /dev/null +++ b/ansible playbooks/keep_pc_from_sleeping.yml @@ -0,0 +1,12 @@ +--- +- name: Keep Windows from sleeping + hosts: windows + gather_facts: false + + tasks: + - name: Disable automatic sleep on AC and battery + ansible.windows.win_command: "powercfg.exe /change {{ item }} 0" + loop: + - standby-timeout-ac + - standby-timeout-dc + changed_when: true \ No newline at end of file diff --git a/ansible playbooks/remove_shutdown_start_menu.yml b/ansible playbooks/remove_shutdown_start_menu.yml new file mode 100644 index 0000000..2670110 --- /dev/null +++ b/ansible playbooks/remove_shutdown_start_menu.yml @@ -0,0 +1,22 @@ +--- +- name: Remove shutdown commands and disable sleep and hibernation + hosts: windows + gather_facts: false + + tasks: + - name: Hide shutdown-related commands for the Ansible user + ansible.windows.win_regedit: + path: HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer + name: NoClose + data: 1 + type: dword + state: present + + - name: Disable automatic sleep and hibernation timeouts + ansible.windows.win_command: "powercfg.exe /change {{ item }} 0" + loop: + - standby-timeout-ac + - standby-timeout-dc + - hibernate-timeout-ac + - hibernate-timeout-dc + changed_when: true \ No newline at end of file diff --git a/ansible playbooks/unblock_shutdown_from_start_menu.yml b/ansible playbooks/unblock_shutdown_from_start_menu.yml new file mode 100644 index 0000000..cc5e131 --- /dev/null +++ b/ansible playbooks/unblock_shutdown_from_start_menu.yml @@ -0,0 +1,49 @@ +--- +- name: Restore shutdown, sleep, and hibernation options + hosts: windows + gather_facts: false + + tasks: + - name: Allow shutdown without logging on + ansible.windows.win_regedit: + path: HKLM:\SOFTWARE\Policies\Microsoft\Windows\System + name: ShutdownWithoutLogon + data: 1 + type: dword + state: present + + - name: Remove shutdown and related restrictions set by policy + ansible.windows.win_regedit: + path: "{{ item.path }}" + name: "{{ item.name }}" + state: absent + loop: + - path: HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer + name: NoClose + - path: HKLM:\SOFTWARE\Policies\Microsoft\Windows\System + name: DisableShutdownOption + - path: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer + name: NoShutdown + - path: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer + name: CloseSystemNoShutdown + - path: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System + name: DisableCACheck + - path: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System + name: DisableTaskMgr + + - name: Restore automatic sleep and hibernation timeouts + ansible.windows.win_command: "powercfg.exe /change {{ item.setting }} {{ item.minutes }}" + loop: + - setting: standby-timeout-ac + minutes: 120 + - setting: standby-timeout-dc + minutes: 120 + - setting: hibernate-timeout-ac + minutes: 180 + - setting: hibernate-timeout-dc + minutes: 30 + changed_when: true + + - name: Enable hibernation + ansible.windows.win_command: powercfg.exe /hibernate on + changed_when: true \ No newline at end of file diff --git a/ansible playbooks/windows_updates_and_defender.yml b/ansible playbooks/windows_updates_and_defender.yml new file mode 100644 index 0000000..674f81c --- /dev/null +++ b/ansible playbooks/windows_updates_and_defender.yml @@ -0,0 +1,37 @@ +--- +- name: Configure Microsoft Defender and install Windows updates + hosts: windows + gather_facts: false + + tasks: + - name: Configure Defender protections and update signatures + ansible.windows.win_powershell: + script: | + $ErrorActionPreference = 'Stop' + + $before = Get-MpPreference + $signatureBefore = (Get-MpComputerStatus).AntivirusSignatureVersion + $settingsChanged = ( + $before.DisableRealtimeMonitoring -ne $false -or + $before.DisableBehaviorMonitoring -ne $false -or + $before.PUAProtection.ToString() -ne 'Enabled' -or + $before.EnableControlledFolderAccess.ToString() -ne 'Enabled' -or + $before.EnableNetworkProtection.ToString() -ne 'Enabled' + ) + + Set-MpPreference -DisableRealtimeMonitoring $false + Set-MpPreference -DisableBehaviorMonitoring $false + Set-MpPreference -PUAProtection Enabled + Set-MpPreference -EnableControlledFolderAccess Enabled + Set-MpPreference -EnableNetworkProtection Enabled + Update-MpSignature + + $signatureAfter = (Get-MpComputerStatus).AntivirusSignatureVersion + $Ansible.Changed = $settingsChanged -or ($signatureBefore -ne $signatureAfter) + + - name: Install all available Windows updates and reboot if required + ansible.windows.win_updates: + category_names: + - '*' + reboot: true + reboot_timeout: 3600 \ No newline at end of file diff --git a/powershell_scripts/keep pc from sleeping or shutting down.ps1 b/powershell_scripts/keep pc from sleeping or shutting down.ps1 new file mode 100644 index 0000000..36eaf22 --- /dev/null +++ b/powershell_scripts/keep pc from sleeping or shutting down.ps1 @@ -0,0 +1,10 @@ +$ErrorActionPreference = 'Stop' + +foreach ($setting in @('standby-timeout-ac', 'standby-timeout-dc')) { + & powercfg.exe /change $setting 0 + if ($LASTEXITCODE -ne 0) { + throw "Failed to set power setting '$setting'." + } +} + +Write-Output 'Automatic sleep is disabled for the current power plan on AC and battery.' diff --git a/powershell_scripts/remove_shutdown_start-menu.ps1 b/powershell_scripts/remove_shutdown_start-menu.ps1 new file mode 100644 index 0000000..53dc861 --- /dev/null +++ b/powershell_scripts/remove_shutdown_start-menu.ps1 @@ -0,0 +1,21 @@ +$ErrorActionPreference = 'Stop' + +$explorerPolicyKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer' +New-Item -Path $explorerPolicyKey -Force | Out-Null +New-ItemProperty -Path $explorerPolicyKey -Name 'NoClose' -PropertyType DWord -Value 1 -Force | Out-Null + +$powerSettings = @( + 'standby-timeout-ac', + 'standby-timeout-dc', + 'hibernate-timeout-ac', + 'hibernate-timeout-dc' +) + +foreach ($setting in $powerSettings) { + & powercfg.exe /change $setting 0 + if ($LASTEXITCODE -ne 0) { + throw "Failed to set power setting '$($setting[0])'." + } +} + +Write-Output 'Shutdown-related Start menu commands are hidden, and automatic sleep/hibernate timeouts are disabled for the current power plan.' diff --git a/powershell_scripts/unblock shutdown from startmenu.ps1 b/powershell_scripts/unblock shutdown from startmenu.ps1 new file mode 100644 index 0000000..df3db5d --- /dev/null +++ b/powershell_scripts/unblock shutdown from startmenu.ps1 @@ -0,0 +1,28 @@ +# Unblock-Computer-Shutdown.ps1 +# Re-enables normal shutdown behavior on Windows 11 +# Run as Administrator, then reboot + +# Remove/Reset all policy keys set by BlockShutdown.ps1 +Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\System' ` + -Name 'ShutdownWithoutLogon' -Value 1 -ErrorAction SilentlyContinue +Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\System' ` + -Name 'DisableShutdownOption' -ErrorAction SilentlyContinue + +Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer' ` + -Name 'NoShutdown' -ErrorAction SilentlyContinue +Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer' ` + -Name 'CloseSystemNoShutdown' -ErrorAction SilentlyContinue + +Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' ` + -Name 'DisableCACheck' -ErrorAction SilentlyContinue +Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' ` + -Name 'DisableTaskMgr' -ErrorAction SilentlyContinue + +# Re-enable sleep and hibernate +powercfg /change standby-timeout-ac 120 | Out-Null +powercfg /change standby-timeout-dc 120 | Out-Null +powercfg /change hibernate-timeout-ac 180 | Out-Null +powercfg /change hibernate-timeout-dc 30 | Out-Null +powercfg /h on + +Write-Host "All shutdown restrictions removed. Reboot for changes to take full effect." -ForegroundColor Green \ No newline at end of file diff --git a/powershell_scripts/windows updates and defender.ps1 b/powershell_scripts/windows updates and defender.ps1 new file mode 100644 index 0000000..32773c7 --- /dev/null +++ b/powershell_scripts/windows updates and defender.ps1 @@ -0,0 +1,11 @@ +#Requires -RunAsAdministrator + +$ErrorActionPreference = 'Stop' + +Update-MpSignature + +Set-MpPreference -DisableRealtimeMonitoring $false +Set-MpPreference -DisableBehaviorMonitoring $false +Set-MpPreference -PUAProtection Enabled +Set-MpPreference -EnableControlledFolderAccess Enabled +Set-MpPreference -EnableNetworkProtection Enabled