Files
test/roles/ensure_log_rotation/tasks/main.yml
T

113 lines
4.0 KiB
YAML

---
# tasks file for ensure_log_rotation
- name: Assert Target OS Is Supported
when:
- ansible_facts["system"] is defined
ansible.builtin.assert:
fail_msg: "Unsupported OS: {{ ansible_facts['distribution'] | default('unknown') }}"
quiet: true
that:
- ansible_facts["system"] == 'Linux'
- >-
ansible_facts["distribution"] in ['AlmaLinux', 'CentOS', 'Debian',
'Fedora', 'OracleLinux', 'Rocky', 'Ubuntu']
- name: Include Variables
ansible.builtin.include_vars:
file: '{{ lookup("first_found", findme) }}'
name: ensure_log_rotation
vars:
findme:
files:
- '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"]
}}-{{ ansible_facts["architecture"] }}.yml'
- '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"]
}}-default.yml'
- '{{ ansible_facts["distribution"] }}-default.yml'
- '{{ ansible_facts["os_family"] }}-{{ ansible_facts["distribution_major_version"]
}}-{{ ansible_facts["architecture"] }}.yml'
- '{{ ansible_facts["os_family"] }}-{{ ansible_facts["distribution_major_version"]
}}-default.yml'
- '{{ ansible_facts["os_family"] }}-default.yml'
- default.yml
paths: [../vars/]
errors: ignore
- name: Package Discovery
when:
- ansible_facts["packages"] is not defined
ansible.builtin.package_facts:
- name: Service Discovery
when:
- ansible_facts["services"] is not defined
ansible.builtin.service_facts:
- name: Ensure Packages
when:
- ensure_log_rotation is defined
- ensure_log_rotation.package_list is defined
- ensure_log_rotation.package_list is iterable
ansible.builtin.package:
name: '{{ item.name }}'
state: '{{ item.state }}'
loop: '{{ ensure_log_rotation.package_list }}'
loop_control:
label: '{{ item.name }} will be {{ item.state }}'
notify:
- Ensure_Log_Rotation.Package_Facts
- Ensure_Log_Rotation.Service_Facts
- name: Ensure Configuration
when:
- ensure_log_rotation is defined
- ensure_log_rotation.template_list is defined
- ensure_log_rotation.template_list is iterable
ansible.builtin.template:
attributes: '{{ item.attributes | default(omit) }}'
backup: '{{ item.backup | default(omit) }}'
dest: '{{ item.dest }}'
follow: '{{ item.follow | default(omit) }}'
force: '{{ item.force | default(omit) }}'
group: '{{ item.group | default(omit) }}'
mode: '{{ item.mode | default(omit) }}'
owner: '{{ item.owner | default(omit) }}'
selevel: '{{ item.selevel | default(omit) }}'
serole: '{{ item.serole | default(omit) }}'
setype: '{{ item.setype | default(omit) }}'
seuser: '{{ item.seuser | default(omit) }}'
src: '{{ item.src | default(omit) }}'
validate: '{{ item.validate | default(omit) }}'
loop: '{{ ensure_log_rotation.template_list }}'
loop_control:
label: '{{ item.dest }}'
notify:
- Ensure_Log_Rotation.Package_Facts
- Ensure_Log_Rotation.Service_Facts
- Ensure_Log_Rotation.Service_Reload
- Ensure_Log_Rotation.Service_Restart
- name: Ensure Services
when:
- ensure_log_rotation is defined
- ensure_log_rotation.service_list is defined
- ensure_log_rotation.service_list is iterable
ansible.builtin.service:
enabled: '{{ item.enabled }}'
name: '{{ item.name }}'
state: '{{ item.state }}'
loop: '{{ ensure_log_rotation.service_list }}'
loop_control:
label: '{{ item.name }} will be {{ item.state }}'
notify:
- Ensure_Log_Rotation.Package_Facts
- Ensure_Log_Rotation.Service_Facts
- name: Flush Handlers
ansible.builtin.meta: flush_handlers
- name: Assert Logrotate Configuration
ansible.builtin.stat:
path: /etc/logrotate.conf
register: _logrotate_stat
- name: Assert Logrotate File Exists
when:
- _logrotate_stat.stat is defined
ansible.builtin.assert:
fail_msg: "/etc/logrotate.conf does not exist"
quiet: true
that:
- _logrotate_stat.stat.exists