Skip to content

Commit

Permalink
promgraf
Browse files Browse the repository at this point in the history
  • Loading branch information
sshresthadh committed Feb 22, 2024
1 parent 0ca2ec4 commit cbcd226
Show file tree
Hide file tree
Showing 22 changed files with 442 additions and 6 deletions.
Binary file modified ansible/roles/.DS_Store
Binary file not shown.
38 changes: 38 additions & 0 deletions ansible/roles/backend/README.md
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).
2 changes: 2 additions & 0 deletions ansible/roles/backend/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for backend
5 changes: 5 additions & 0 deletions ansible/roles/backend/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# handlers file for backend
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: yes
52 changes: 52 additions & 0 deletions ansible/roles/backend/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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.1

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

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.
42 changes: 42 additions & 0 deletions ansible/roles/backend/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- name: Clone a Git repository
ansible.builtin.git:
repo: https://github.com/sshresthadh/devops-class.git
dest: /home/ubuntu/test
version: main

- name: Install the gpg key for nodejs LTS
apt_key:
url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
state: present

- name: Install the nodejs LTS repos
apt_repository:
repo: "deb https://deb.nodesource.com/node_14.x focal main"
state: present
update_cache: yes

- name: Install the nodejs
apt:
name: nodejs
state: present

- name: NPM Install
shell: >
cd /home/ubuntu/test/all_in_docker/server
npm i
- name: Create systemd service file
ansible.builtin.template:
src: backend.j2 # Path to your systemd service template file
dest: /etc/systemd/system/backend.service
notify: Reload systemd

- name: Start and enable the service
ansible.builtin.service:
name: backend
state: started
enabled: yes
notify: Reload systemd


31 changes: 31 additions & 0 deletions ansible/roles/backend/templates/backend.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[Unit]

Description=Your Node.js Backend

After=network.target



[Service]

Environment=NODE_ENV=production

ExecStart=/usr/bin/node index.js

WorkingDirectory=/home/ubuntu/devops-class/all_in_docker/server

Restart=always

RestartSec=10

StandardOutput=syslog

StandardError=syslog

SyslogIdentifier=client



[Install]

WantedBy=multi-user.target
2 changes: 2 additions & 0 deletions ansible/roles/backend/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions ansible/roles/backend/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- backend
2 changes: 2 additions & 0 deletions ansible/roles/backend/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for backend
3 changes: 3 additions & 0 deletions ansible/roles/grafana/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#defining variables
---
download_url: "https://github.com/grafana/agent/releases/download/v{{ agent_version }}/agent-{{ linux_architecture }}.zip"
36 changes: 36 additions & 0 deletions ansible/roles/grafana/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: Add the Grafana GPG key and APT repository
become: yes
shell: |
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" --yes
- name: Update apt
apt:
update_cache: yes

- name: Install grafana through apt
ansible.builtin.apt:
name: grafana
state: latest
install_recommends: yes

- name: Reload the SystemD to re-read configurations and start grafana
become: yes
systemd:
daemon-reload: yes
name: grafana-server
enabled: yes
state: started

- name: set nginx conf file for prometheus
become: true
ansible.builtin.template:
src: grafana-conf.j2
dest: /etc/nginx/sites-enabled/grafana.conf

- name: restart nginx
service:
name: nginx
state: restarted

29 changes: 29 additions & 0 deletions ansible/roles/grafana/templates/grafana-conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
server {
server_name grafana.deerhold.com;

location / {
proxy_set_header Host $http_host;
proxy_pass http://localhost:3000/;
}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/grafana.deerhold.com-0001/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/grafana.deerhold.com-0001/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
if ($host = grafana.deerhold.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 80;
listen [::]:80;
server_name grafana.deerhold.com;
return 404; # managed by Certbot


}
5 changes: 5 additions & 0 deletions ansible/roles/mysql/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Restart mysql
service:
name: mysql
state: restarted
7 changes: 3 additions & 4 deletions ansible/roles/mysql/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@
service:
name: apparmor
state: restarted
notify: Restart mysql


- name: Restart MySQL service
service:
name: mysql
state: restarted


4 changes: 4 additions & 0 deletions ansible/roles/nginx/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: restart nginx
service:
name: nginx
state: restarted
3 changes: 2 additions & 1 deletion ansible/roles/nginx/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- name: start nginx
service:
name: nginx
state: started
state: stopped
notify: restart nginx


4 changes: 4 additions & 0 deletions ansible/roles/prometheus/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#defining variables
---
prometheus_version: "2.31"
download_url: "https://github.com/prometheus/prometheus/releases/download/v2.31.0/prometheus-2.31.0.linux-amd64.tar.gz"
Loading

0 comments on commit cbcd226

Please sign in to comment.