This commit is contained in:
2026-09-17 00:36:31 +02:00
parent 8efcc9eac6
commit 6e5b63a3ad
13 changed files with 320 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
+3
View File
@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
---
# defaults file for roles/disable-wakers
+9
View File
@@ -0,0 +1,9 @@
---
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true
- name: Restart ACPI wakeup service
ansible.builtin.systemd:
name: "{{ acpi_wakeup_service_name }}"
state: restarted
+35
View File
@@ -0,0 +1,35 @@
#SPDX-License-Identifier: MIT-0
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.2
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
+26
View File
@@ -0,0 +1,26 @@
---
- name: Install ACPI wakeup shutdown script
ansible.builtin.template:
src: disable-acpi-wakeup.sh.j2
dest: "{{ acpi_wakeup_script_path }}"
owner: root
group: root
mode: "0755"
- name: Install ACPI wakeup systemd service
ansible.builtin.template:
src: disable-acpi-wakeup.service.j2
dest: "/etc/systemd/system/{{ acpi_wakeup_service_name }}"
owner: root
group: root
mode: "0644"
notify:
- Reload systemd
- Restart ACPI wakeup service
- name: Enable ACPI wakeup shutdown service
ansible.builtin.systemd:
name: "{{ acpi_wakeup_service_name }}"
enabled: true
state: started
daemon_reload: true
@@ -0,0 +1,15 @@
[Unit]
Description=Disable ACPI wakeup devices on shutdown
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target poweroff.target
Conflicts=shutdown.target reboot.target halt.target poweroff.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecStop={{ acpi_wakeup_script_path }}
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,8 @@
#!/bin/bash
set -u
for device in $(awk '$3 == "enabled" {print $1}' /proc/acpi/wakeup); do
echo "$device"
echo "$device" > /proc/acpi/wakeup
done
+3
View File
@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
localhost
+6
View File
@@ -0,0 +1,6 @@
#SPDX-License-Identifier: MIT-0
---
- hosts: localhost
remote_user: root
roles:
- roles/disable-wakers
+3
View File
@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
---
# vars file for roles/disable-wakers
+153
View File
@@ -0,0 +1,153 @@
- name: Setup vault SSH keys
become: "{{ 'no' if inventory_hostname in ['sectorq.cloud', 'nas.home.lan'] else 'yes' }}"
block:
- name: Include vault
ansible.builtin.include_vars:
file: init.yml
- name: Install required dependencies
ansible.builtin.dnf:
name:
- dnf-plugins-core
- curl
state: present
- name: Add HashiCorp repository
ansible.builtin.get_url:
url: https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
dest: /etc/yum.repos.d/hashicorp.repo
mode: "0644"
- name: Clean DNF cache
ansible.builtin.command: dnf clean all
changed_when: false
- name: Install Vault
ansible.builtin.dnf:
name: vault
state: present
update_cache: yes
- name: Set vault address
copy:
dest: /etc/profile.d/vault.sh
content: "export VAULT_ADDR=http://vault.home.lan:8205\n"
owner: root
group: root
mode: '0644'
- name: Read SSH CA public key from Vault
ansible.builtin.command:
cmd: vault read -field=public_key ssh/config/ca
register: vault_ca
changed_when: false
environment:
VAULT_ADDR: "{{ vault_addr }}"
VAULT_TOKEN: "{{ vault_token }}"
- name: Install trusted SSH user CA
ansible.builtin.copy:
content: "{{ vault_ca.stdout }}\n"
dest: /etc/ssh/trusted-user-ca-keys.pem
owner: root
group: root
mode: '0644'
- name: Enable Trusted User CA
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regexp: "^TrustedUserCAKeys"
line: "TrustedUserCAKeys /etc/ssh/trusted-user-ca-keys.pem"
state: present
- name: Enable PubkeyAuthentication
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regexp: "^PubkeyAuthentication.*"
line: "PubkeyAuthentication yes"
state: present
- name: Create vault agent dir
file:
path: /etc/vault-agent
state: directory
owner: root
group: root
mode: '0644'
- name: Create vault agent config
copy:
dest: /etc/vault-agent/config.hcl
content: |
vault {
address = "http://vault.home.lan:8205"
}
auto_auth {
method "token_file" {
config = {
token_file_path = "/etc/vault-agent/token"
}
}
sink "file" {
config = {
path = "/tmp/vault-token"
}
}
}
template {
destination = "/home/jd/.ssh/id_ed25519-cert.pub"
perms = "0644"
user = "jd"
group = "jd"
contents = <<EOH
{{ '{{' }} with secret "ssh/sign/admin" (printf "public_key=%s" (trimSpace (file "/home/jd/.ssh/id_ed25519.pub"))) "valid_principals=jd" {{ '}}' }}
{{ '{{' }} .Data.signed_key {{ '}}' }}
{{ '{{' }} end {{ '}}' }}
EOH
}
owner: root
group: root
mode: '0644'
- name: Create file with token for vault agent
copy:
dest: /etc/vault-agent/token
content: "{{ vault_sshcert_token }}"
owner: root
group: root
mode: '0600'
- name: Create service for vault agent
copy:
dest: /etc/systemd/system/vault-agent.service
content: |
[Unit]
Description=Vault Agent
After=network-online.target
[Service]
ExecStart=/usr/bin/vault agent -config=/etc/vault-agent/config.hcl
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.target
owner: root
group: root
mode: '0644'
- name: Enable and start vault agent service
systemd:
name: vault-agent
enabled: yes
state: started
- name: Restart sshd
ansible.builtin.service:
name: sshd
state: restarted
@@ -0,0 +1,13 @@
[Unit]
Description=Run command before shutdown
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/usr/local/bin/pre-shutdown.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
echo "System is shutting down at $(date)" >> /var/log/pre-shutdown.log
for i in `cat /proc/acpi/wakeup|grep enabled|awk '{ print $1 }'`
do
echo $i
echo $i > /proc/acpi/wakeup
done