add playbooks and power shell scripts

add playbooks and power shell scripts
This commit is contained in:
WickedYoda committed 2026-10-21 12:59:57 -05:00
1 parent 377688e218
commit 4d5c390d46
9 files changed
+324

No files matched your search

+134
View File
@@ -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'
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.'
@@ -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.'
@@ -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
@@ -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