# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low
- name: Ensure zIPL bootmap is up to date
  block:

  - name: Obtain stats of /boot/bootmap
    ansible.builtin.stat:
      path: /boot/bootmap
    register: boot_bootmap

  - name: Obtain stats of /etc/zipl.conf
    ansible.builtin.stat:
      path: /etc/zipl.conf
    register: zipl_conf

  - name: Obtain stats of /boot/loader/entries
    ansible.builtin.stat:
      path: /boot/loader/entries
    register: boot_loader_entries

  - name: Update zIPL bootmap
    ansible.builtin.command: /usr/sbin/zipl
    changed_when: true
    when:
    - boot_bootmap.stat.mtime is defined
    - zipl_conf.stat.mtime is defined
    - boot_loader_entries.stat.mtime is defined
    - boot_bootmap.stat.mtime < zipl_conf.stat.mtime or boot_bootmap.stat.mtime <
      boot_loader_entries.stat.mtime
  when:
  - ansible_architecture == "s390x"
  - ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman", "container"]
  tags:
  - configure_strategy
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
  - zipl_bootmap_is_up_to_date
