# platform = multi_platform_all
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low

- (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: yes
  register: edit_sudoers_passwd_timeout_option

- name: Enable passwd_timeout option with appropriate value in /etc/sudoers
  ansible.builtin.lineinfile: # noqa 503
    path: /etc/sudoers
    line: 'Defaults passwd_timeout={{ var_sudo_passwd_timeout }}'
    validate: /usr/sbin/visudo -cf %s
  when: edit_sudoers_passwd_timeout_option is defined and not edit_sudoers_passwd_timeout_option.changed
