# 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
  - medium_severity
  - no_reboot_needed
  - restrict_strategy
  - sudo_add_passwd_timeout
- (xccdf-var var_sudo_passwd_timeout)

- name: Ensure passwd_timeout is enabled with the appropriate value in /etc/sudoers
  ansible.builtin.lineinfile:
    path: /etc/sudoers
    regexp: ^[\s]*Defaults\s(.*)\bpasswd_timeout=[-]?.+\b(.*)$
    line: Defaults \1passwd_timeout={{ var_sudo_passwd_timeout }}\2
    validate: /usr/sbin/visudo -cf %s
    backrefs: true
  register: edit_sudoers_passwd_timeout_option
  when: '"linux-base" in ansible_facts.packages'
  tags:
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
  - restrict_strategy
  - sudo_add_passwd_timeout

- name: Enable passwd_timeout option with appropriate value in /etc/sudoers
  ansible.builtin.lineinfile:
    path: /etc/sudoers
    line: Defaults passwd_timeout={{ var_sudo_passwd_timeout }}
    validate: /usr/sbin/visudo -cf %s
  when:
  - '"linux-base" in ansible_facts.packages'
  - edit_sudoers_passwd_timeout_option is defined and not edit_sudoers_passwd_timeout_option.changed
  tags:
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
  - restrict_strategy
  - sudo_add_passwd_timeout
