- name: Check for filename fail: msg: Must set logrotate_file_name for logfile to rotate when: logrotate_file_name is not defined # Hash the full path to avoid any conflicts but remain idempotent. # "/var/log/ansible/ansible.log" becomes "ansible.log.37237.conf" for example - name: Create a unique config name set_fact: logrotate_generated_config_file_name: "{{ logrotate_file_name | basename }}.{{ (logrotate_file_name|hash('sha1'))[0:5] }}.conf" - name: 'Install {{ logrotate_file_name }} rotatation config file' template: src: logrotate.conf.j2 dest: '/etc/logrotate.d/{{ logrotate_config_file_name|default(logrotate_generated_config_file_name) }}' owner: root group: root mode: 0644