# platform = multi_platform_all
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low
- name: Gather the package facts
  package_facts:
    manager: auto
  tags:
  - low_complexity
  - low_disruption
  - low_severity
  - no_reboot_needed
  - restrict_strategy
  - sshd_use_strong_rng

- name: Setting unquoted shell-style assignment of 'SSH_USE_STRONG_RNG' to '32' in
    '/etc/sysconfig/sshd'
  block:

  - name: Check for duplicate values
    ansible.builtin.lineinfile:
      path: /etc/sysconfig/sshd
      create: true
      regexp: (?i)^\s*SSH_USE_STRONG_RNG=
      state: absent
    check_mode: true
    changed_when: false
    register: dupes

  - name: Deduplicate values from /etc/sysconfig/sshd
    ansible.builtin.lineinfile:
      path: /etc/sysconfig/sshd
      create: true
      regexp: (?i)^\s*SSH_USE_STRONG_RNG=
      state: absent
    when: dupes.found is defined and dupes.found > 1

  - name: Insert correct line to /etc/sysconfig/sshd
    ansible.builtin.lineinfile:
      path: /etc/sysconfig/sshd
      create: true
      regexp: (?i)^\s*SSH_USE_STRONG_RNG=
      line: SSH_USE_STRONG_RNG=32
      state: present
      insertbefore: ^# SSH_USE_STRONG_RNG
      validate: /usr/bin/bash -n %s
  when: '"linux-base" in ansible_facts.packages'
  tags:
  - low_complexity
  - low_disruption
  - low_severity
  - no_reboot_needed
  - restrict_strategy
  - sshd_use_strong_rng
