From f1be7a65dad45db0d01298098f9e1839af3ae48a Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Tue, 4 Aug 2020 13:11:25 +0300 Subject: [PATCH] Add variables to control logging options Added 2 variables - pacemaker_corosync_use_logfile and pacemaker_corosync_use_syslog which you can enable/disable to controll where corosync log will be written to. --- defaults/main.yml | 2 ++ tasks/pacemaker.yml | 7 +++++++ templates/corosync.conf.j2 | 12 +++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 319646e..30238a7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,5 @@ pacemaker_corosync_fqdn: false pacemaker_corosync_group: false pacemaker_corosync_ring_interface: false +pacemaker_corosync_use_syslog: true +pacemaker_corosync_use_logfile: false diff --git a/tasks/pacemaker.yml b/tasks/pacemaker.yml index 2420ce8..69943c8 100644 --- a/tasks/pacemaker.yml +++ b/tasks/pacemaker.yml @@ -79,12 +79,19 @@ owner: root notify: Restart corosync +- name: Creates log directory + file: + path: /var/log/corosync + state: directory + when: pacemaker_corosync_use_logfile | bool is true + - name: Adds logrotate config for corosync template: src: corosync_logrotate.conf.j2 dest: /etc/logrotate.d/corosync mode: "0644" owner: root + when: pacemaker_corosync_use_logfile | bool is true - name: Creates services directory file: diff --git a/templates/corosync.conf.j2 b/templates/corosync.conf.j2 index e212057..cf8514c 100644 --- a/templates/corosync.conf.j2 +++ b/templates/corosync.conf.j2 @@ -1,3 +1,4 @@ +{% set _pacemaker_corosync_bind_addr = hostvars[inventory_hostname]['ansible_' + pacemaker_corosync_ring_interface | replace('-', '_')].ipv4.address %} totem { version: 2 cluster_name: {{ pacemaker_corosync_group }} @@ -6,7 +7,7 @@ totem { {% endif %} interface { ringnumber: 0 - bindnetaddr: {{ hostvars[inventory_hostname]['ansible_' + pacemaker_corosync_ring_interface | replace('-', '_')].ipv4.address }} + bindnetaddr: {{ _pacemaker_corosync_bind_addr }} broadcast: yes mcastport: 5405 } @@ -29,7 +30,7 @@ quorum { nodelist { {% for node in groups[pacemaker_corosync_group]|sort %} node { - ring0_addr: {{ hostvars[node]['ansible_' + pacemaker_corosync_ring_interface].ipv4.address }} + ring0_addr: {{ _pacemaker_corosync_bind_addr }} name: {{ pacemaker_corosync_fqdn | bool | ternary(hostvars[node].ansible_fqdn, node) }} nodeid: {{ loop.index }} } @@ -38,9 +39,10 @@ nodelist { {% endif %} logging { - to_logfile: yes + to_logfile: {{ (pacemaker_corosync_use_logfile | bool) | ternary('yes', 'no') }} + {% if pacemaker_corosync_use_logfile | bool %} logfile: /var/log/corosync/corosync.log - to_syslog: yes + {% endif %} + to_syslog: {{ (pacemaker_corosync_use_syslog | bool) | ternary('yes', 'no') }} timestamp: on } -