Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a global handlers role #455

Merged
merged 12 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/global_handlers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- "global_handlers: Introduce a global handlers role (oravirt#455)"
5 changes: 5 additions & 0 deletions roles/global_handlers/.ansibledoctor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
logging:
level: warning
template: readme
force_overwrite: true
50 changes: 50 additions & 0 deletions roles/global_handlers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# global_handlers

Collection of handlers includeable by other roles.

Make them available to your role by including it into the
dependency list in meta/main.yml of your role, for instance.

## Table of content

- [Requirements](#requirements)
- [Default Variables](#default-variables)
- [restart_on_requirement](#restart_on_requirement)
- [Dependencies](#dependencies)
- [License](#license)
- [Author](#author)

---

## Requirements

- Minimum Ansible version: `2.14.0`

## Default Variables

### restart_on_requirement

Controls if reboot handler actually reboots the host (true)
or just displays a reboot advice (false)

**_Type:_** bool<br />

#### Default value

```YAML
restart_on_requirement: true
```



## Dependencies

None.

## License

license (MIT)

## Author

[Thilo Solbrig]
7 changes: 7 additions & 0 deletions roles/global_handlers/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# @var restart_on_requirement:description: >
# Controls if reboot handler actually reboots the host (true)
# or just displays a reboot advice (false)
# @end
# @var restart_on_requirement:type: bool
restart_on_requirement: true
24 changes: 24 additions & 0 deletions roles/global_handlers/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: Reboot concerning package updates

Check warning on line 2 in roles/global_handlers/handlers/main.yml

View workflow job for this annotation

GitHub Actions / build

jinja[spacing]

Jinja2 spacing could be improved: {%- if ansible_facts.os_family == 'RedHat' -%} yum needs-restarting -r {%- elif ansible_facts.os_family == 'Suse' -%} zypper needs-rebooting {%- endif -%} -> {%- if ansible_facts.os_family == 'RedHat' -%} yum needs-restarting -r{%- elif ansible_facts.os_family == 'Suse' -%} zypper needs-rebooting{%- endif -%}
ansible.builtin.command:
"{%- if ansible_facts.os_family == 'RedHat' -%}
yum needs-restarting -r
{%- elif ansible_facts.os_family == 'Suse' -%}
zypper needs-rebooting
{%- endif -%}"
failed_when: false
register: _global_handlers_needs_restarting
changed_when: _global_handlers_needs_restarting.rc > 0
notify: restart server

- name: "restart server block (on behalf of 'restart server')"
block:
- name: Reboot
when: restart_on_requirement
listen: restart server
ansible.builtin.reboot:
- name: Reboot recommendation
when: not restart_on_requirement
listen: restart server
ansible.builtin.debug:
msg: Please REBOOT {{ ansible_hostname }} for modifications to take effect.
31 changes: 31 additions & 0 deletions roles/global_handlers/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# @meta description: >
# Collection of handlers includeable by other roles.
#
# Make them available to your role by including it into the
# dependency list in meta/main.yml of your role, for instance.
# @end
# @meta author: [Thilo Solbrig]
galaxy_info:
role_name: global_handlers
author: Thilo Solbrig
description: Collection of handlers includeable by other roles (e.g., via meta dependencies)
company: ASPICON GmbH
license: license (MIT)

min_ansible_version: 2.14.0

platforms:
- name: EL
versions:
- "6"
- "7"
- "8"
- "9"
- name: SLES
versions:
- "15"

galaxy_tags: []

dependencies: []
Loading