Skip to content

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 / END line to /var/log/linuxfabrik-lfops.log on the target host. Includes the playbook name as well as run/skip tags. No-op in --check mode and on Windows. Used as pre_tasks / post_tasks in every LFOps playbook.
  • Parameters: none.

print-messages.yml

  • Prints the messages roles collected in __shared__end_of_play_messages as one block, so the operator sees every manual step in one place directly above the PLAY RECAP instead of scattered over a long run. Skipped when nothing was collected, and clears the list afterwards so the next play of a playbooks/all.yml run does not repeat it. Used as post_tasks in every LFOps playbook, next to log-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>.yml files 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>.yml files (role_path, not the calling role), using the same least-to-most-specific order as platform-variables.yml. Imported in every playbook's pre_tasks so 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.yml belongs in the calling role's validation block: it refuses lfops__reboot_now on a host without /usr/local/sbin/schedule-reboot before the role writes anything, and registers the stat result the other file reads. request-reboot.yml files the reboot request, performs the reboot right away when lfops__reboot_now is 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.yml at once, see "Preflight Checks" in the docs/developer-guide/roles.md. Import it in the pre_tasks of a playbook that runs many roles, tagged always, so that a missing or wrongly typed variable of a late role aborts the run before the first role changes the host. Roles without meta/argument_specs.yml are 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-repo on the Ansible controller (delegate_to: localhost, serialized with throttle: 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 of main, 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 to main), a tag like 'v1.2.3', or a bare version like '1.2.3' (auto-prefixed with v).

clone-monitoring-plugins-repo.yml

  • Same as clone-lib-repo.yml but for the Linuxfabrik Monitoring Plugins. Target on the controller: /tmp/ansible.monitoring-plugins-repo.
  • Parameters:

    • shared__monitoring_plugins_repo_dest: Optional. Same semantics as shared__lib_repo_dest. Default: /tmp/ansible.monitoring-plugins-repo.
    • shared__monitoring_plugins_version: Mandatory. Same semantics as shared__lib_version.

remove-rpmnew-rpmsave.yml

  • Removes <file>.rpmnew, <file>.rpmsave, <file>.dpkg-dist and <file>.ucf-dist for a single config file. Only runs when lfops__remove_rpmnew_rpmsave is true (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 / .rpmsave suffix).

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 a Persistent=true timer 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'

License

The Unlicense

Author Information

Linuxfabrik GmbH, Zurich