#  Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
---

- name: Install mailx and postfix
  package:
    name: "{{ mail_packages }}"
    state: present

- name: Start postfix service
  systemd:
    name: postfix
    state: started

- name: Fetch ansible-playbook path
  command: whereis ansible-playbook
  changed_when: false
  register: ansible_playbook_path

- name: Schedule cron job for alerting
  cron:
    name: Auth failure alerting
    special_time: hourly
    job: "{{ ansible_playbook_path.stdout.split(' ')[1] }} {{ role_path }}/files/auth_failure_check.yml -e 'alert_email_address={{ alert_email_address }}'"