Compare commits

...

3 commits

Author SHA1 Message Date
6bb69cc080
temp: reboot test playbook
Some checks failed
/ Ansible Lint (push) Failing after 1m52s
/ Ansible Lint (pull_request) Failing after 2m6s
2025-07-01 03:41:57 +02:00
1c729ade06
reboot(role): intro. reboot role, which handles local conns. gracefully 2025-07-01 03:41:57 +02:00
249ff5f958
temp: connection test 2025-07-01 03:41:57 +02:00
6 changed files with 63 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,15 @@
---
- name: reboot test
hosts: all
tasks:
- name: debug before
ansible.builtin.debug:
msg: before
- name: reboot
ansible.builtin.include_role:
name: 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"