--- - name: Ensure state is valid ansible.builtin.fail: msg: >-2 Invalid state '{{ alertmanager_state }}'! Valid states are {{ alertmanager_states | join(', ') }}. when: alertmanager_state not in alertmanager_states - name: Ensure deployment method is valid ansible.builtin.fail: msg: >-2 Invalid deployment method {{ alertmanager_deployment_method }}! Supported deployment methods are {{ alertmanager_deployment_methods | join(', ') }}. when: alertmanager_deployment_method not in alertmanager_deployment_methods - name: Ensure alertmanager user '{{ alertmanager_user }}' is {{ alertmanager_state }} ansible.builtin.user: name: "{{ alertmanager_user }}" state: "{{ alertmanager_state }}" system: true register: alertmanager_user_info - name: Ensure mounts are {{ alertmanager_state }} ansible.builtin.file: dest: "{{ item.path }}" state: "{{ (alertmanager_state == 'present') | ternary('directory', 'absent') }}" owner: "{{ item.owner | default(alertmanager_user_info.uid | default(alertmanager_user)) }}" group: "{{ item.owner | default(alertmanager_user_info.group | default(alertmanager_user)) }}" mode: "{{ item.mode | default('0755') }}" loop: - path: "{{ alertmanager_base_path }}" - path: "{{ alertmanager_data_path }}" - path: "{{ alertmanager_config_path }}" - name: Ensure config file is templated ansible.builtin.copy: dest: "{{ alertmanager_config_file }}" content: "{{ alertmanager_config | to_nice_yaml }}" owner: "{{ alertmanager_user_info.uid | default(alertmanager_user) }}" group: "{{ alertmanager_user_info.group | default(alertmanager_user) }}" mode: "0640" when: alertmanager_state == 'present' notify: - restart-alertmanager - name: Deploy alertmanager using {{ alertmanager_deployment_method }} ansible.builtin.include_tasks: file: "deploy-{{ alertmanager_deployment_method }}.yml"