From fa6cee404f8011b72cb2ea4a99d79dc44b0168cf Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotjagov Date: Fri, 28 Sep 2018 18:09:25 +0300 Subject: [PATCH 1/3] Added ability to specify daemon launch arguments. It may be used for providing extra args for keepalived daemon. With these args it's possible to change logging options or enabling SNMP checks. --- defaults/main.yml | 12 ++++++++++++ tasks/main.yml | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 9f7bdd9..9088748 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -55,3 +55,15 @@ keepalived_bind_on_non_local: False # Example: #keepalived_global_defs: # - enable_script_security + +# Set location of keepalived daemon options file path +# For Debian based systems it's usually /etc/default/keepalived +# For RedHat based systems it's usually /etc/sysconfig/keepalived +keepalived_daemon_options_file_path: "" + +# Overriding keepalived daemon extra arguments, which will be applied inside of +# the keepalived_daemon_options_file_path variable. +# Example: +#keepalived_daemon_default_options_overrides: +# - "DAEMON_ARGS='--snmp'" +keepalived_daemon_default_options_overrides: [] diff --git a/tasks/main.yml b/tasks/main.yml index f1e5ccc..54bd002 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -45,7 +45,7 @@ tags: - keepalived-install -- name: configure keepalived +- name: Configure keepalived template: src: keepalived.conf.j2 dest: "{{ keepalived_config_file_path }}" @@ -54,6 +54,21 @@ notify: - restart keepalived +- name: Configure keepalived extra params + lineinfile: + line: "{{ item }}" + regexp: "^{{ item.split('=')[0] }}" + dest: "{{ keepalived_daemon_options_file_path }}" + state: present + with_items: "{{ keepalived_daemon_default_options_overrides }}" + when: + - keepalived_daemon_default_options_overrides is defined + - keepalived_daemon_options_file_path is defined + tags: + - keepalived-config + notify: + - restart keepalived + - name: Dropping the tracking scripts copy: src: "{{ item.value.src_check_script }}" From ea194db6409fa671a84d310f0b3a5f63bf444c48 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotjagov Date: Tue, 9 Oct 2018 15:40:23 +0300 Subject: [PATCH 2/3] provided os specific defaults for deamon options file Added check of daemon options file --- defaults/main.yml | 2 +- tasks/main.yml | 11 +++++++---- vars/debian.yml | 1 + vars/redhat.yml | 1 + vars/suse.yml | 1 + vars/ubuntu-14.04.yml | 5 +++++ vars/ubuntu-16.04.yml | 6 ++++++ 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 9088748..af00dad 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -59,7 +59,7 @@ keepalived_bind_on_non_local: False # Set location of keepalived daemon options file path # For Debian based systems it's usually /etc/default/keepalived # For RedHat based systems it's usually /etc/sysconfig/keepalived -keepalived_daemon_options_file_path: "" +keepalived_daemon_options_file_path: "{{ _keepalived_daemon_options_file_path }}" # Overriding keepalived daemon extra arguments, which will be applied inside of # the keepalived_daemon_options_file_path variable. diff --git a/tasks/main.yml b/tasks/main.yml index 54bd002..e5e77fe 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -54,16 +54,19 @@ notify: - restart keepalived +- name: Check that daemon options file exists + stat: + path: "{{ keepalived_daemon_options_file_path }}" + register: keepalived_daemon_options_file + - name: Configure keepalived extra params lineinfile: line: "{{ item }}" regexp: "^{{ item.split('=')[0] }}" dest: "{{ keepalived_daemon_options_file_path }}" state: present - with_items: "{{ keepalived_daemon_default_options_overrides }}" - when: - - keepalived_daemon_default_options_overrides is defined - - keepalived_daemon_options_file_path is defined + with_items: "{{ keepalived_daemon_default_options_overrides }}" + when: keepalived_daemon_options_file.stat.exists tags: - keepalived-config notify: diff --git a/vars/debian.yml b/vars/debian.yml index cddb25a..5e06ffb 100644 --- a/vars/debian.yml +++ b/vars/debian.yml @@ -17,6 +17,7 @@ keepalived_package_name: "keepalived" keepalived_service_name: "keepalived" keepalived_config_file_path: "/etc/keepalived/keepalived.conf" +_keepalived_daemon_options_file_path: "/etc/default/keepalived" # Debian is WIP, and only native packages from the distribution are supported for now. keepalived_ubuntu_src: "native" #no support of ppas under debian -> forced source to be native diff --git a/vars/redhat.yml b/vars/redhat.yml index 0379a32..d0ee9b8 100644 --- a/vars/redhat.yml +++ b/vars/redhat.yml @@ -17,3 +17,4 @@ keepalived_package_name: "keepalived" keepalived_service_name: "keepalived" keepalived_config_file_path: "/etc/keepalived/keepalived.conf" +_keepalived_daemon_options_file_path: "/etc/sysconfig/keepalived" diff --git a/vars/suse.yml b/vars/suse.yml index 890b3a8..aa5f220 100644 --- a/vars/suse.yml +++ b/vars/suse.yml @@ -16,3 +16,4 @@ keepalived_package_name: "keepalived" keepalived_service_name: "keepalived" keepalived_config_file_path: "/etc/keepalived/keepalived.conf" +_keepalived_daemon_options_file_path: "/etc/sysconfig/keepalived" diff --git a/vars/ubuntu-14.04.yml b/vars/ubuntu-14.04.yml index afb9a63..03a8e6d 100644 --- a/vars/ubuntu-14.04.yml +++ b/vars/ubuntu-14.04.yml @@ -18,6 +18,11 @@ keepalived_package_name: "keepalived" keepalived_service_name: "keepalived" keepalived_config_file_path: "/etc/keepalived/keepalived.conf" +# As ppa has more fresh version of keepalived package, +# daemon file path and structure as for redhat systems. +# Ubuntu native package uses different location. +_keepalived_daemon_options_file_path: "/etc/sysconfig/keepalived" + ## Repo details for keepalived ppa keepalived_ppa_repo: "ppa:keepalived/stable" keepalived_ppa_keyid: "7C33BDC6" diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml index 893ba4b..e47af0d 100644 --- a/vars/ubuntu-16.04.yml +++ b/vars/ubuntu-16.04.yml @@ -18,6 +18,12 @@ keepalived_package_name: "keepalived" keepalived_service_name: "keepalived.service" keepalived_config_file_path: "/etc/keepalived/keepalived.conf" +# As native repo has more fresh version of keepalived package, +# daemon file path is the default one. +# PPA package uses different location and file structure, +# like redhat. +_keepalived_daemon_options_file_path: "/etc/default/keepalived" + ## Repo details for keepalived ppa keepalived_ppa_repo: "ppa:keepalived/stable" keepalived_ppa_keyid: "7C33BDC6" From 50b4e9e72ce79e0c863ebf2e729904ff9b453cdf Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotjagov Date: Wed, 10 Oct 2018 15:44:02 +0300 Subject: [PATCH 3/3] Added missed tag for "Check that daemon options file exists" task --- tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasks/main.yml b/tasks/main.yml index e5e77fe..1f6b9c2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -58,6 +58,8 @@ stat: path: "{{ keepalived_daemon_options_file_path }}" register: keepalived_daemon_options_file + tags: + - keepalived-config - name: Configure keepalived extra params lineinfile: