Skip to content

Commit

Permalink
Merge branch 'master' into dejal
Browse files Browse the repository at this point in the history
  • Loading branch information
Dejal committed Sep 24, 2024
2 parents a4f827d + e7284bd commit 4346304
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 41 deletions.
6 changes: 3 additions & 3 deletions ansible/inventories/digital_ocean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugin: constructed
strict: False

groups:

haproxy: inventory_hostname.startswith('www')

web: inventory_hostname.startswith('app')
Expand All @@ -12,6 +11,7 @@ groups:
counts: inventory_hostname.startswith('app-counts')
push: inventory_hostname.startswith('app-push')
blogs: inventory_hostname.startswith('blog')
forum: inventory_hostname.startswith('forum')

node: inventory_hostname.startswith('node')
node_socket: inventory_hostname.startswith('node-socket')
Expand All @@ -25,9 +25,9 @@ groups:
task: inventory_hostname.startswith('task')
celery: inventory_hostname.startswith('task-celery')
work: inventory_hostname.startswith('task-work')

staging: inventory_hostname.startswith('staging')

db: inventory_hostname.startswith('db')
search: inventory_hostname.startswith('db-elasticsearch')
elasticsearch: inventory_hostname.startswith('db-elasticsearch')
Expand Down
8 changes: 4 additions & 4 deletions ansible/inventories/hetzner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ plugin: constructed
strict: False

groups:

hall: inventory_hostname.startswith('h')

haproxy: inventory_hostname.startswith('hwww')

app: inventory_hostname.startswith('happ')
Expand All @@ -20,6 +19,7 @@ groups:
push: inventory_hostname.startswith('happ-push')
hpush: inventory_hostname.startswith('happ-push')
blogs: inventory_hostname.startswith('blog')
forum: inventory_hostname.startswith('hforum')

node: inventory_hostname.startswith('hnode')
hnode: inventory_hostname.startswith('hnode')
Expand All @@ -40,9 +40,9 @@ groups:
task: inventory_hostname.startswith('htask')
celery: inventory_hostname.startswith('htask-celery')
work: inventory_hostname.startswith('htask-work')

staging: inventory_hostname.startswith('hstaging')

hdb: inventory_hostname.startswith('hdb')
db: inventory_hostname.startswith('hdb')
search: inventory_hostname.startswith('hdb-elasticsearch')
Expand Down
24 changes: 12 additions & 12 deletions ansible/playbooks/setup_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
vars:
- update_apt_cache: yes
- motd_role: app

roles:
- {role: 'base', tags: 'base'}
- {role: 'ufw', tags: 'ufw'}
- {role: 'docker', tags: 'docker'}
- {role: 'repo', tags: ['repo', 'pull']}
- {role: 'dnsmasq', tags: 'dnsmasq'}
- {role: 'consul', tags: 'consul'}
- {role: 'consul-client', tags: 'consul'}
- {role: 'web', tags: 'web'}
- {role: 'nginx', tags: 'nginx'}
- {role: 'node-exporter', tags: ['node-exporter', 'metrics']}
- { role: "base", tags: "base" }
- { role: "ufw", tags: "ufw" }
- { role: "docker", tags: "docker" }
- { role: "repo", tags: ["repo", "pull"] }
- { role: "dnsmasq", tags: "dnsmasq" }
- { role: "consul", tags: "consul" }
- { role: "consul-client", tags: "consul" }

- { role: "web", tags: "web" }
- { role: "nginx", tags: "nginx" }
- { role: "node-exporter", tags: ["node-exporter", "metrics"] }
20 changes: 20 additions & 0 deletions ansible/playbooks/setup_forum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: SETUP -> forum containers
hosts: forum
vars_files:
- ../env_vars/base.yml
vars:
- update_apt_cache: yes
- motd_role: app

roles:
- { role: "base", tags: "base" }
- { role: "ufw", tags: "ufw" }
- { role: "docker", tags: "docker" }
- { role: "repo", tags: ["repo", "pull"] }
- { role: "dnsmasq", tags: "dnsmasq" }
- { role: "consul", tags: "consul" }
- { role: "consul-client", tags: "consul" }

- { role: "forum", tags: "forum" }
- { role: "node-exporter", tags: ["node-exporter", "metrics"] }
16 changes: 8 additions & 8 deletions ansible/playbooks/setup_metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
- motd_role: db

roles:
# - {role: 'base', tags: 'base'}
# - {role: 'ufw', tags: 'ufw'}
# - {role: 'docker', tags: 'docker'}
# - {role: 'repo', tags: ['repo', 'pull']}
# - {role: 'dnsmasq', tags: 'dnsmasq'}
# - {role: 'consul', tags: 'consul'}
# - {role: 'consul-client', tags: 'consul'}
# - {role: 'mongo-exporter', tags: 'mongo-exporter'}
- { role: "base", tags: "base" }
- { role: "ufw", tags: "ufw" }
- { role: "docker", tags: "docker" }
- { role: "repo", tags: ["repo", "pull"] }
- { role: "dnsmasq", tags: "dnsmasq" }
- { role: "consul", tags: "consul" }
- { role: "consul-client", tags: "consul" }
- { role: "mongo-exporter", tags: "mongo-exporter" }
- { role: "postgres-exporter", tags: "postgres-exporter" }
- { role: "redis-exporter", tags: "redis-exporter" }
- { role: "node-exporter", tags: ["node-exporter", "metrics"] }
Expand Down
11 changes: 11 additions & 0 deletions ansible/roles/forum/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: restart discourse
become: yes
docker_container:
name: discourse
state: restarted

- name: reload ufw
become: yes
service:
name: ufw
state: reloaded
20 changes: 20 additions & 0 deletions ansible/roles/forum/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Register forum in consul
tags: consul
become: yes
template:
src: consul_service.json
dest: /etc/consul.d/forum.json
when: disable_consul_services_ie_staging is not defined
notify:
- reload consul

- name: Allow http
become: yes
ufw: rule=allow port=80
tags: ufw

- name: Allow https
become: yes
ufw: rule=allow port=443
tags: ufw
10 changes: 10 additions & 0 deletions ansible/roles/forum/templates/consul_service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"service": {
"name": "{{ inventory_hostname|regex_replace('\d+', '') }}",
"id": "{{ inventory_hostname }}",
"tags": [
"forum"
],
"port": 80
}
}
5 changes: 2 additions & 3 deletions ansible/roles/prometheus/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- name: Template file for prometheus
vars:
monitor_server: "{{ 'staging.newsblur.com' if disable_consul_services_ie_staging is defined else 'newsblur.com' }}"
Expand Down Expand Up @@ -27,12 +26,12 @@
user: root
networks_cli_compatible: yes
network_mode: default
command: --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --storage.tsdb.retention.time=10y
command: --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --storage.tsdb.retention.time=10y --storage.tsdb.retention.size=500GB
networks:
- name: newsblurnet
state: started
ports:
- 9090:9090
- 9090:9090
restart_policy: unless-stopped
container_default_behavior: no_defaults
volumes:
Expand Down
21 changes: 10 additions & 11 deletions ansible/roles/ufw/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
---

- name: Set hosts
set_fact:
hetzner_hosts: "{{ groups['hall'] | map('extract', hostvars, ['ansible_host']) }}"
do_hosts: "{{ groups['NewsBlur_Docker'] | map('extract', hostvars, ['ansible_host']) }}"

- name: Generate UFW batch script
become: yes
template:
src: ufw_rules.sh.j2
dest: /tmp/ufw_rules.sh
mode: '0755'
mode: "0755"

# - name: Stop ufw and delete all rules
# become: yes
# ufw: state=reset
Expand Down Expand Up @@ -51,14 +50,14 @@
# tags:
# - firewall
# - ufw

# - name: Allow all access from Hetzner inventory hosts
# become: yes
# ufw:
# rule: allow
# src: '{{ item }}'
# with_items: "{{ groups['hall'] | map('extract', hostvars, ['ansible_host']) }}"
# tags:
# tags:
# - firewall
# - ufw
# - hetzner_firewall
Expand All @@ -71,7 +70,7 @@
# route: yes
# src: '{{ item }}'
# with_items: "{{ groups['hall'] | map('extract', hostvars, ['ansible_host']) }}"
# tags:
# tags:
# - firewall
# - ufw
# - hetzner_firewall
Expand All @@ -84,7 +83,7 @@
# src: '{{ item }}'
# with_items: "{{ groups['oldandnew'] | map('extract', hostvars, ['ansible_host']) }}"
# when: "'oldandnew' in groups"
# tags:
# tags:
# - firewall
# - ufw

Expand All @@ -95,7 +94,7 @@
# src: '{{ item }}'
# with_items: "{{ groups['NewsBlur_Docker'] | map('extract', hostvars, ['ansible_host']) }}"
# when: "'oldandnew' not in groups"
# tags:
# tags:
# - firewall
# - ufw

Expand All @@ -107,7 +106,7 @@
# src: '{{ item }}'
# with_items: "{{ groups['NewsBlur_Docker'] | map('extract', hostvars, ['ansible_host']) }}"
# when: "'oldandnew' not in groups"
# tags:
# tags:
# - firewall
# - ufw

Expand Down Expand Up @@ -145,7 +144,7 @@
COMMIT
# END UFW AND DOCKER
tags: docker
tags: docker ufw
notify: restart ufw

- name: Start ufw
Expand Down
2 changes: 2 additions & 0 deletions ansible/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
when: "'app' in group_names"
- import_playbook: playbooks/setup_blog.yml
when: "'blogs' in group_names"
- import_playbook: playbooks/setup_forum.yml
when: "'forum' in group_names"
- import_playbook: playbooks/setup_www.yml
when: "'haproxy' in group_names"
- import_playbook: playbooks/setup_node.yml
Expand Down
10 changes: 10 additions & 0 deletions docker/haproxy/haproxy.consul.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ frontend public
use_backend node_page if { path_beg /original_page/ }
use_backend blog if { hdr_end(host) -i blog.newsblur.com }
use_backend sentry if { hdr_end(host) -i sentry.newsblur.com }
use_backend forum if { hdr_end(host) -i forum.newsblur.com }
use_backend forum if { hdr_end(host) -i forum2.newsblur.com }
use_backend forum if { hdr_end(host) -i forum3.newsblur.com }
use_backend nginx if { path_beg /media/ }
use_backend nginx if { path_beg /static/ }
use_backend nginx if { path_beg /favicon }
Expand Down Expand Up @@ -196,6 +199,13 @@ backend sentry
server {{host}} {{host}}.node.nyc1.consul:9000
{% endfor %}

backend forum
balance roundrobin
default-server check inter 2000ms resolvers consul resolve-prefer ipv4 resolve-opts allow-dup-ip init-addr none
{% for host in groups.forum %}
server {{host}} {{host}}.node.nyc1.consul:80
{% endfor %}

backend db_metrics
balance roundrobin
# option httpchk GET /_haproxychk
Expand Down

0 comments on commit 4346304

Please sign in to comment.