Compare commits
3 commits
835e6c5838
...
6bb69cc080
Author | SHA1 | Date | |
---|---|---|---|
6bb69cc080 |
|||
1c729ade06 |
|||
249ff5f958 |
6 changed files with 63 additions and 0 deletions
7
playbooks/connection_test.yaml
Normal file
7
playbooks/connection_test.yaml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
- name: connection test
|
||||||
|
hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: debug
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: ansible_connection
|
15
playbooks/reboot_test.yaml
Normal file
15
playbooks/reboot_test.yaml
Normal 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
12
roles/reboot/README.md
Normal 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`.
|
2
roles/reboot/defaults/main.yaml
Normal file
2
roles/reboot/defaults/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
reboot__local_handling: none
|
||||||
|
reboot__local_handling_file: /var/run/ansible-reboot-required
|
13
roles/reboot/meta/argument_specs.yaml
Normal file
13
roles/reboot/meta/argument_specs.yaml
Normal 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
|
14
roles/reboot/tasks/main.yaml
Normal file
14
roles/reboot/tasks/main.yaml
Normal 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"
|
Loading…
Add table
Add a link
Reference in a new issue