From 1841644cb74c093244785cb36445634bf16faf9e Mon Sep 17 00:00:00 2001 From: Davis Raymond Date: Fri, 4 Mar 2022 12:33:04 +0300 Subject: [PATCH] Add support for RedHat deployments (#26) --- tasks/main.yml | 10 ++++++++-- tasks/redhat.yml | 23 +++++++++++++++++++++++ tasks/setup.yml | 16 +++++++++++++--- tasks/ubuntu.yml | 1 + vars/redhat.yml | 3 +++ vars/ubuntu.yml | 3 +++ 6 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 tasks/redhat.yml create mode 100644 vars/redhat.yml create mode 100644 vars/ubuntu.yml diff --git a/tasks/main.yml b/tasks/main.yml index 3e4d14c..f6d329e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,11 +1,17 @@ --- +- include_vars: redhat.yml + when: ansible_facts["os_family"] == "RedHat" + +- include_vars: ubuntu.yml + when: ansible_facts["os_family"] == "Debian" + - include_tasks: setup.yml when: monit_setup_mode - name: Copy monit config files template: src: "templates/etc/monit/conf.d/{{ item }}" - dest: "/etc/monit/conf.d/{{ item }}" + dest: "{{ monit_includes }}/{{ item }}" mode: 0644 with_items: "{{ monit_scripts }}" notify: @@ -15,7 +21,7 @@ - name: Copy monit template config files template: src: "templates/etc/monit/conf.d/{{ item }}" - dest: "/etc/monit/conf.d/{{ item }}-{{ service_name }}" + dest: "{{ monit_includes }}/{{ item }}-{{ service_name }}" mode: 0644 with_items: "{{ monit_template_scripts }}" notify: diff --git a/tasks/redhat.yml b/tasks/redhat.yml new file mode 100644 index 0000000..f232128 --- /dev/null +++ b/tasks/redhat.yml @@ -0,0 +1,23 @@ +--- +- name: Add epel-release (CentOS) + yum: + name: epel-release + state: latest + when: ansible_distribution == 'CentOS' + +- name: Add RPM Key + rpm_key: + key: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }} + when: ansible_distribution == 'RedHat' + +- name: Add epel-release (RedHat) + yum: + name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm + state: latest + when: ansible_distribution == 'RedHat' + +- name: Install Monit (RedHat) + yum: + name: monit + state: latest + diff --git a/tasks/setup.yml b/tasks/setup.yml index 66d8485..6ca0d41 100644 --- a/tasks/setup.yml +++ b/tasks/setup.yml @@ -2,17 +2,26 @@ - include_tasks: ubuntu.yml when: ansible_distribution == 'Ubuntu' +- include_tasks: redhat.yml + when: ansible_facts['os_family'] == "RedHat" + +- include_vars: redhat.yml + when: ansible_facts["os_family"] == "RedHat" + +- include_vars: ubuntu.yml + when: ansible_facts["os_family"] == "Debian" + - name: Copy monitrc configuration file template: src: "templates/etc/monit/monitrc.j2" - dest: "/etc/monit/monitrc" + dest: "{{ monit_configuration_path }}" mode: 0600 notify: - restart monit - name: Delete monit config files directory file: - path: /etc/monit/conf.d + path: "{{ monit_includes }}" state: absent ignore_errors: yes notify: @@ -20,7 +29,7 @@ - name: Create monit config files directory file: - path: /etc/monit/conf.d + path: "{{ monit_includes }}" state: directory mode: 0755 owner: root @@ -50,4 +59,5 @@ - name: Enable the Monit service service: name: monit + state: started enabled: yes diff --git a/tasks/ubuntu.yml b/tasks/ubuntu.yml index 1e027c4..e0cd714 100644 --- a/tasks/ubuntu.yml +++ b/tasks/ubuntu.yml @@ -8,3 +8,4 @@ - { package: monit, version: "{{ monit_version }}"} notify: - restart monit + diff --git a/vars/redhat.yml b/vars/redhat.yml new file mode 100644 index 0000000..d821ae9 --- /dev/null +++ b/vars/redhat.yml @@ -0,0 +1,3 @@ +--- +monit_includes: "/etc/monit.d" +monit_configuration_path: "/etc/monitrc" diff --git a/vars/ubuntu.yml b/vars/ubuntu.yml new file mode 100644 index 0000000..fa45e3d --- /dev/null +++ b/vars/ubuntu.yml @@ -0,0 +1,3 @@ +--- +monit_includes: "/etc/monit/conf.d" +monit_configuration_path: "/etc/monit/monitrc"