Created
November 5, 2018 12:29
-
-
Save filipecifali/1d76dd7cef26b1ad94106a473d6156e0 to your computer and use it in GitHub Desktop.
roles/monit/tasks/main.yml
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: get installed packages | |
package_facts: {} | |
- name: checking if monit version differs | |
debug: "msg='Version {{ monit_full_version }} is not installed, only {{ (ansible_facts.packages.monit | map(attribute='version')) | join(', ') }}'" | |
changed_when: true | |
when: monit_full_version not in (ansible_facts.packages.monit | map(attribute='version')) | |
register: monit_installed_version | |
- name: remove current installed package | |
apt: | |
name: monit | |
state: absent | |
when: monit_reinstall or monit_installed_version.changed | |
- set_fact: | |
sha256_value: "{{ item.split(' ')[0] }}" | |
with_url: "{{ monit_checksum_url }}" | |
tags: testing | |
when: monit_reinstall or monit_installed_version.changed | |
- name: download monit debfile | |
get_url: | |
url: "{{ monit_url }}" | |
checksum: "sha256:{{ sha256_value }}" | |
dest: "/tmp/{{ monit_debfile }}" | |
when: monit_reinstall or monit_installed_version.changed | |
- name: monit debfile install | |
apt: | |
deb: "/tmp/{{ monit_debfile }}" | |
dpkg_options: "skip-same-version" | |
register: dpkg_result | |
changed_when: dpkg_result.stderr.find("already installed") == -1 | |
when: monit_reinstall or monit_installed_version.changed | |
notify: | |
- enable Monit | |
- restart Monit | |
- name: clean up debfile | |
file: | |
path: "/tmp/{{ monit_debfile }}" | |
state: absent | |
- name: create necessary paths | |
file: path={{ item.path }} state={{ item.state }} | |
with_items: | |
- { path: /usr/local/share/man/man1, state: directory } | |
- { path: /var/lib/monit, state: directory } | |
- { path: /etc/monit/conf.d, state: directory } | |
- name: copy Monit init and config files | |
template: src={{ item.src }} dest={{ item.dest }} mode={{ item.mode }} | |
with_items: | |
- { src: monit.init.j2, dest: /etc/init.d/monit, mode: "0755" } | |
- { src: monit.default.j2, dest: /etc/default/monit, mode: "0644" } | |
- { src: monitrc.j2, dest: /etc/monit/monitrc, mode: "0600" } | |
notify: | |
- restart Monit | |
- name: reload systemd service files | |
command: systemctl daemon-reload | |
when: ansible_distribution_release != 'wheezy' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment