Ansible Role linuxfabrik.lfops.shared¶
This role bundles helper tasks reused across other LFOps roles and playbooks. It is not designed to be run as a whole; instead, callers import individual tasks via import_role / include_role with tasks_from:.
Available since LFOps 2.0.1.
Available Tasks¶
log-start.yml and log-end.yml
- Append a
START/ENDline to/var/log/linuxfabrik-lfops.logon the target host. Includes the playbook name as well as run/skip tags. No-op in--checkmode and on Windows. Used aspre_tasks/post_tasksin every LFOps playbook. - Parameters: none.
print-messages.yml
- Prints the messages roles collected in
__shared__end_of_play_messagesas one block, so the operator sees every manual step in one place directly above thePLAY RECAPinstead of scattered over a long run. Skipped when nothing was collected, and clears the list afterwards so the next play of aplaybooks/all.ymlrun does not repeat it. Used aspost_tasksin every LFOps playbook, next tolog-end.yml. - Parameters: none. Reads
__shared__end_of_play_messages, see the "Reporting a Manual Step to the Operator" section of the docs/developer-guide/roles.md.
platform-variables.yml
- Loads OS-family / distribution / version-specific
vars/<name>.ymlfiles of the calling role, in order from least to most specific (e.g.RedHat.yml->RedHat8.yml->Rocky.yml->Rocky8.yml->Rocky8.10.yml). Missing files are skipped silently. - Parameters: none. Relies on
ansible_parent_role_paths[0](i.e. it must be imported from another role).
global-variables.yml
- Loads LFOps-wide platform variables from the shared role's own
vars/<name>.ymlfiles (role_path, not the calling role), using the same least-to-most-specific order asplatform-variables.yml. Imported in every playbook'spre_tasksso the variables are available to all roles in the play. - Parameters: none.
assert-reboot-possible.yml and request-reboot.yml
- The two halves of the reboot pattern, see the "Reboots" section of the docs/developer-guide/roles.md.
assert-reboot-possible.ymlbelongs in the calling role's validation block: it refuseslfops__reboot_nowon a host without/usr/local/sbin/schedule-rebootbefore the role writes anything, and registers the stat result the other file reads.request-reboot.ymlfiles the reboot request, performs the reboot right away whenlfops__reboot_nowis set, or reports the pending reboot to the operator when the mechanism is not deployed. Include it gated on the calling role's own "a reboot is needed" condition. - Parameters of
assert-reboot-possible.yml: none. -
Parameters of
request-reboot.yml:shared__reboot_reason: Mandatory. Spool file name, by convention the role name.shared__reboot_detail: Mandatory. What changed, in lower case. Goes into the notification mail, followed by the name of the calling role, and into the message the operator sees.
assert-disk-space.yml
- Aborts the run if a filesystem has less free space than the given requirements need, see "Preflight Checks" in the docs/developer-guide/roles.md. Requirements that end up on the same filesystem are added up, and a requirement whose software is already installed is dropped. Skipped with
lfops__skip_disk_space_check. -
Parameters:
-
shared__disk_space_requirements: Mandatory. List of dictionaries with these subkeys:creates: Optional. A file or directory that exists once the software is installed. If it exists, the requirement is dropped.name: Mandatory. What needs the space, shown in the error message.path: Mandatory. An existing path on the filesystem to check, for example/usr.required_mib: Mandatory. The free space needed, in MiB.
-
validate-role-arguments.yml
- Validates the variables of several roles against their
meta/argument_specs.ymlat once, see "Preflight Checks" in the docs/developer-guide/roles.md. Import it in thepre_tasksof a playbook that runs many roles, taggedalways, so that a missing or wrongly typed variable of a late role aborts the run before the first role changes the host. Roles withoutmeta/argument_specs.ymlare skipped. -
Parameters:
shared__validate_role_arguments_roles: Mandatory. List of role names, without the collection prefix.
clone-lib-repo.yml
- Clones the Linuxfabrik Python Libraries to
/tmp/ansible.lib-repoon the Ansible controller (delegate_to: localhost, serialized withthrottle: 1,--check-safe). Includes a rescue path that wipes the directory and retries on failure (e.g. when an existing checkout is on a different ref). -
Parameters:
shared__lib_repo_dest: Optional. A directory of its own for the state to check out, named after a tag or a resolved commit ofmain, e.g./var/tmp/lfops/<role>/lib-v1.2.3. A checkout found there is used as it is and never fetched again, so further hosts find it without asking GitHub. Default:/tmp/ansible.lib-repo, shared by all versions and updated on every call.shared__lib_version: Mandatory. The git ref to check out. Accepts'dev'(resolved tomain), a tag like'v1.2.3', or a bare version like'1.2.3'(auto-prefixed withv).
clone-monitoring-plugins-repo.yml
- Same as
clone-lib-repo.ymlbut for the Linuxfabrik Monitoring Plugins. Target on the controller:/tmp/ansible.monitoring-plugins-repo. -
Parameters:
shared__monitoring_plugins_repo_dest: Optional. Same semantics asshared__lib_repo_dest. Default:/tmp/ansible.monitoring-plugins-repo.shared__monitoring_plugins_version: Mandatory. Same semantics asshared__lib_version.
remove-rpmnew-rpmsave.yml
- Removes
<file>.rpmnew,<file>.rpmsave,<file>.dpkg-distand<file>.ucf-distfor a single config file. Only runs whenlfops__remove_rpmnew_rpmsaveistrue(LFOps-wide opt-in, see the main README). -
Parameters:
shared__remove_rpmnew_rpmsave_config_file: Mandatory. Absolute path of the deployed config file (without the.rpmnew/.rpmsavesuffix).
reload-changed-timers.yml
- Reloads systemd after the unit file or a drop-in of calendar timers changed, without letting a timer run at once because of its new schedule. systemd computes the next run of a calendar timer from its last run, so a schedule moved to a point between the last run and now, for example from weekly to daily, fires as soon as the manager loads it. The task stops and disables the given timers, runs
systemctl daemon-reload, which unloads them together with their last run, sets the stamp file of aPersistent=truetimer to now (systemd reads the last run back from it on start), and then enables and starts each one again if it was before. Include it right after the role deployed its units and before anything else reloads systemd, see "Calendar Timers" in the docs/developer-guide/systemd.md. Does nothing if the list is empty. -
Parameters:
shared__reload_changed_timers: Mandatory. List of the timer units whose unit file or drop-in changed in this run, e.g.['update-and-reboot.timer'].shared__reload_changed_timers_user: Optional. User whose service manager runs the timers (systemctl --user). Default: unset (the system manager).
Usage Example¶
- name: 'Set LFOps-wide platform variables'
ansible.builtin.import_role:
name: 'shared'
tasks_from: 'global-variables.yml'
tags:
- 'always'
- name: 'Set platform/version specific variables'
ansible.builtin.import_role:
name: 'shared'
tasks_from: 'platform-variables.yml'
tags:
- 'always'
- name: 'Remove rpmnew / rpmsave'
ansible.builtin.include_role:
name: 'shared'
tasks_from: 'remove-rpmnew-rpmsave.yml'
vars:
shared__remove_rpmnew_rpmsave_config_file: '/etc/example/example.conf'