Compare commits

...

3 commits

Author SHA1 Message Date
835e6c5838
reboot(role): intro. reboot role, which handles local conns. gracefully
Some checks failed
/ Ansible Lint (push) Failing after 1m58s
2025-07-01 03:38:46 +02:00
7616f9a568
temp: connection test
Some checks failed
/ Ansible Lint (push) Failing after 3m44s
2025-07-01 03:18:54 +02:00
22bb558b5c
temp: reboot test playbook
Some checks failed
/ Ansible Lint (push) Failing after 1m49s
2025-06-30 22:26:33 +02:00
6 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,7 @@
---
- name: connection test
hosts: all
tasks:
- name: debug
ansible.builtin.debug:
var: ansible_connection

View file

@ -0,0 +1,14 @@
---
- name: reboot test
hosts: all
tasks:
- name: debug before
ansible.builtin.debug:
msg: before
- name: reboot
ansible.builtin.reboot:
- name: debug after
ansible.builtin.debug:
msg: after

12
roles/reboot/README.md Normal file
View file

@ -0,0 +1,12 @@
# Role `reboot`
A role for rebooting a host, which also handles local connections gracefully.
## Optional Arguments
- `reboot__local_handling`: How to handle reboot on local connections. The default mode is `none`.
Possible choices:
- `none`: Just runs `ansible.builtin.reboot`, which would fail on local connections.
- `ignore`: Just doesn't reboot on local connections.
- `file`: Doesn't reboot on local connections and instead touches the file defined by `reboot__local_handling_file`.
- `reboot__local_handling_file`: The file to touch, if `reboot__local_handling` is `file`. Defaults to `/var/run/ansible-reboot-required`.

View file

@ -0,0 +1,2 @@
reboot__local_handling: none
reboot__local_handling_file: /var/run/ansible-reboot-required

View file

@ -0,0 +1,13 @@
argument_specs:
main:
options:
reboot__local_handling:
type: str
required: false
choices:
- "none"
- "ignore"
- "file"
reboot__local_handling_file:
type: path
required: false

View file

@ -0,0 +1,14 @@
- name: Reboot
ansible.builtin.reboot:
become: true
when: ansible_connection != "local" or reboot__local_handling == "none"
- name: Touch a reboot required file
ansible.builtin.file:
path: "{{ reboot__local_handling_file }}"
state: touch
owner: root
group: root
mode: "0644"
become: true
when: ansible_connection == "local" and reboot__local_handling == "file"