Migrated to ansible roles
This commit is contained in:
10
roles/nginx-loadbalancer/meta/main.yml
Normal file
10
roles/nginx-loadbalancer/meta/main.yml
Normal file
@ -0,0 +1,10 @@
|
||||
galaxy_info:
|
||||
author: strNophix
|
||||
description: Nginx Loadbalancer Role
|
||||
|
||||
license: MIT
|
||||
min_ansible_version: 2.1
|
||||
|
||||
galaxy_tags: []
|
||||
|
||||
dependencies: []
|
24
roles/nginx-loadbalancer/tasks/main.yml
Normal file
24
roles/nginx-loadbalancer/tasks/main.yml
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
# tasks file for nginx-loadbalancer
|
||||
- name: Install nginx
|
||||
package:
|
||||
name: nginx
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: true
|
||||
- name: Move config to vm
|
||||
ansible.builtin.template:
|
||||
src: ./templates/loadbalancer.cfg.j2
|
||||
dest: /etc/nginx/sites-available/nginx.cfg
|
||||
become: true
|
||||
- name: Enable loadbalancer config
|
||||
file:
|
||||
src: /etc/nginx/sites-available/nginx.cfg
|
||||
dest: /etc/nginx/sites-enabled/default
|
||||
state: link
|
||||
become: true
|
||||
- name: Restart nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: restarted
|
||||
become: true
|
13
roles/nginx-loadbalancer/templates/loadbalancer.cfg.j2
Normal file
13
roles/nginx-loadbalancer/templates/loadbalancer.cfg.j2
Normal file
@ -0,0 +1,13 @@
|
||||
upstream app {
|
||||
{% for host in groups['webserver'] %}
|
||||
server {{ host }}:80;
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
location / {
|
||||
proxy_pass http://app;
|
||||
}
|
||||
}
|
7
roles/nginx-webserver/handlers/main.yml
Normal file
7
roles/nginx-webserver/handlers/main.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
# handlers file for nginx-webserver
|
||||
- name: restart nginx
|
||||
ansible.builtin.service:
|
||||
name: nginx
|
||||
state: restarted
|
||||
become: true
|
10
roles/nginx-webserver/meta/main.yml
Normal file
10
roles/nginx-webserver/meta/main.yml
Normal file
@ -0,0 +1,10 @@
|
||||
galaxy_info:
|
||||
author: strNophix
|
||||
description: Nginx Webserver Role
|
||||
|
||||
license: MIT
|
||||
min_ansible_version: 2.1
|
||||
|
||||
galaxy_tags: []
|
||||
|
||||
dependencies: []
|
14
roles/nginx-webserver/tasks/main.yml
Normal file
14
roles/nginx-webserver/tasks/main.yml
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
# tasks file for nginx-webserver
|
||||
- name: Install nginx
|
||||
package:
|
||||
name: nginx
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: true
|
||||
notify: restart nginx
|
||||
- name: Copy over index.html
|
||||
ansible.builtin.template:
|
||||
src: ./templates/index.html.j2
|
||||
dest: /var/www/html/index.html
|
||||
become: true
|
17
roles/nginx-webserver/templates/index.html.j2
Normal file
17
roles/nginx-webserver/templates/index.html.j2
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Hello</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>Hostname: {{ ansible_facts.nodename }}</p>
|
||||
<p>OS: {{ ansible_facts.distribution }} {{ ansible_facts.distribution_version }}</p>
|
||||
<p>Kernel: {{ ansible_facts.kernel }}</p>
|
||||
<p>Memory usage: {{ ansible_facts.memfree_mb }}/{{ ansible_facts.memtotal_mb }}MB</p>
|
||||
<p>Python version: {{ ansible_facts.python_version }}</p>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user