-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ansible #932
add ansible #932
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## Documentation: Using Ansible to Configure Monit on a Server | ||
|
||
## Introduction | ||
|
||
This documentation provides a guide on configuring Monit on a server using Ansible. Monit is a process supervision tool that monitors services and restarts them if they fail. Ansible automates the setup of Monit configurations, ensuring consistency across environments. | ||
|
||
## Prerequisites | ||
|
||
- Ansible installed on your local machine | ||
- SSH access to the target server | ||
|
||
## Ansible Playbook Breakdown | ||
|
||
The playbook for Monit setup typically consists of the following tasks: | ||
|
||
- Install Monit: Installs the Monit package on the server. | ||
- Copy Monit Configuration Templates: Places your custom Monit configuration files in the appropriate directory. | ||
- Start and Enable Monit: Ensures Monit is started and set to start on boot. | ||
|
||
## Running the Ansible Playbook | ||
|
||
Run the playbook from the Ansible directory with the following command for production environment: | ||
|
||
``` | ||
ansible-playbook -i ./inventory-prod.yml ./monit-role.yml | ||
``` | ||
|
||
or | ||
|
||
``` | ||
ansible-playbook -i ./inventory-dev.yml ./monit-role.yml | ||
``` | ||
|
||
for development environment | ||
|
||
## Accessing to monit | ||
|
||
Monit is accessible on the port `2812` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
webservers: | ||
hosts: | ||
monit: | ||
ansible_host: 34.133.234.147 | ||
ansible_user: andrii_khomik | ||
ansible_ssh_private_key: ~/.ssh/gcp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
webservers: | ||
hosts: | ||
monit: | ||
ansible_host: 34.136.62.183 | ||
ansible_user: andrii_khomik | ||
ansible_ssh_private_key: ~/.ssh/gcp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- name: use monit role playbook | ||
hosts: monit | ||
become: true | ||
|
||
roles: | ||
- role: monit | ||
system_manager: [email protected] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Role Name | ||
========= | ||
|
||
A brief description of the role goes here. | ||
|
||
Requirements | ||
------------ | ||
|
||
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. | ||
|
||
Dependencies | ||
------------ | ||
|
||
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: | ||
|
||
- hosts: servers | ||
roles: | ||
- { role: username.rolename, x: 42 } | ||
|
||
License | ||
------- | ||
|
||
BSD | ||
|
||
Author Information | ||
------------------ | ||
|
||
An optional section for the role authors to include contact information, or a website (HTML is not allowed). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
# defaults file for monit |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
check process nginx with pidfile /run/nginx.pid | ||
start program = "/usr/sbin/service nginx start" with timeout 60 seconds | ||
stop program = "/usr/sbin/service nginx stop" | ||
if failed host 127.0.0.1 port 443 protocol https for 3 cycles then alert | ||
if failed host 127.0.0.1 port 443 protocol https for 3 cycles then restart | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а чому тут алерт не даєш? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
check process postgresql with pidfile /var/run/postgresql/12-main.pid | ||
start program = "/bin/systemctl postgresql start" | ||
stop program = "/bin/systemctl postgresql stop" | ||
if failed port 5432 then alert |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
check process redis with pidfile /var/run/redis/redis-server.pid | ||
start program = "/usr/sbin/service redis-server start" | ||
stop program = "/usr/sbin/service redis-server stop" | ||
|
||
if failed host 127.0.0.1 port 6379 | ||
then restart | ||
if 5 restarts within 5 cycles | ||
then alert |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- name: Restart monit | ||
service: | ||
name: monit | ||
state: restarted | ||
Comment on lines
+2
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а що це таке? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Хандлер для перезавантаження моніту при встановленні, використовуєтьс в головному конфігураційному файлі |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
galaxy_info: | ||
author: your name | ||
description: your role description | ||
company: your company (optional) | ||
|
||
# If the issue tracker for your role is not on github, uncomment the | ||
# next line and provide a value | ||
# issue_tracker_url: http://example.com/issue/tracker | ||
|
||
# Choose a valid license ID from https://spdx.org - some suggested licenses: | ||
# - BSD-3-Clause (default) | ||
# - MIT | ||
# - GPL-2.0-or-later | ||
# - GPL-3.0-only | ||
# - Apache-2.0 | ||
# - CC-BY-4.0 | ||
license: license (GPL-2.0-or-later, MIT, etc) | ||
|
||
min_ansible_version: 2.16.3 | ||
|
||
# If this a Container Enabled role, provide the minimum Ansible Container version. | ||
# min_ansible_container_version: | ||
|
||
galaxy_tags: [] | ||
# List tags for your role here, one per line. A tag is a keyword that describes | ||
# and categorizes the role. Users find roles by searching for tags. Be sure to | ||
# remove the '[]' above, if you add tags to this list. | ||
# | ||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters. | ||
# Maximum 20 tags per role. | ||
|
||
dependencies: [] | ||
# List your role dependencies here, one per line. Be sure to remove the '[]' above, | ||
# if you add dependencies to this list. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
- name: Install Monit | ||
apt: | ||
name: monit | ||
state: present | ||
|
||
- name: Ensure Monit is enabled and started | ||
systemd: | ||
name: monit | ||
enabled: yes | ||
state: started | ||
|
||
- name: Copy Redis Monit config | ||
copy: | ||
dest: /etc/monit/conf.d/redis | ||
src: files/redis | ||
|
||
- name: Copy Postgres Monit config | ||
copy: | ||
dest: /etc/monit/conf.d/postgresql | ||
src: files/postgresql | ||
|
||
- name: Copy Redis Nginx config | ||
copy: | ||
dest: /etc/monit/conf.d/nginx | ||
src: files/nginx | ||
|
||
- name: Include encrypted secrets | ||
include_vars: | ||
file: vars/secrets.yml | ||
|
||
- name: Copy monit template config files | ||
template: | ||
src: "templates/monitrc.j2" | ||
dest: "/etc/monit/monitrc" | ||
|
||
- name: Reload monit to apply configuration | ||
command: monit reload | ||
notify: | ||
- Restart monit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Конфіг для перезавантаження сервісу, пропоную залишити