Ansible: How to prevent suspend/standby/hibernate using systemd masking

Method: See ‘How do I disable my system from going to sleep?’ on AskUbuntu

---
- name: Disable system sleep and hibernation
  hosts: all
  become: true  # Required for systemd operations
  tasks:
    - name: Mask system sleep-related targets
      systemd:
        name: "{{ item }}"
        masked: true
      loop:
        - sleep.target
        - suspend.target
        - hibernate.target
        - hybrid-sleep.target
      tags:
        - power
        - systemd