Last active
November 13, 2021 21:35
-
-
Save Harsimran1/40de6cb867008e80dc6b5d1c39f24da6 to your computer and use it in GitHub Desktop.
Create log file and enable log rotation using Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: "Create or ensure log dir" | |
file: | |
path: "/var/log" | |
state: directory | |
recurse: yes | |
mode: "0755" | |
owner: "my_service_user" | |
group: "my_service" | |
- name: "create log file" | |
file: | |
path: "/var/log/my_service" | |
state: touch | |
mode: "0644" | |
owner: "my_service_user" | |
group: "my_service" | |
- name: "Create logrotate config file" | |
file: | |
path: "/etc/logrotate.d/my_service" | |
state: touch | |
mode: "0644" | |
owner: "my_service_user" | |
group: "my_service" | |
- name: "Add config block to logrotate config file" | |
blockinfile: | |
path: "/etc/logrotate.d/my_service" | |
block: | | |
/var/log/my_service { | |
maxsize 100M | |
copytruncate | |
notifempty | |
missingok | |
compress | |
delaycompress | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment