Skip to content

Commit

Permalink
Add initial logic for tier0 mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanspw committed Jul 29, 2024
1 parent 8458d0f commit 787a647
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 14 deletions.
14 changes: 14 additions & 0 deletions group_vars/mirrors_tier0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
mirror_path: /repo
mirror_path_use_subdir: false
mirror_custom_ssl: true
mirror_create_fs: false
mirror_bootstrap_mirror: false
mirror_configure_crons: false
rsync_modules:
almalinux:
path: "{{ mirror_path }}/almalinux"
comment: AlmaLinux repository
almalinux-elevate:
path: "{{ mirror_path }}/elevate"
comment: AlmaLinux ELevate repository
20 changes: 11 additions & 9 deletions hosts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,24 @@ almalinux-mirror.yucca.net
[el7_mirrors]
el7.repo.almalinux.org

[matrix_synapse]
almalinux.im ansible_host=170.249.201.58

[matrix_synapse_stg]
stg.almalinux.im
[mirrors_tier0]
#atl.rsync.repo.almalinux.org
#sea.rsync.repo.almalinux.org
fra.rsync.repo.almalinux.org
hnd.rsync.repo.almalinux.org

[mirrors:children]
mirrors_tier0
aws_mirrors
azure_mirrors
external_managed_mirrors
el7_mirrors

[mirrors_tier0]
#atl.rsync.repo.almalinux.org
#sea.rsync.repo.almalinux.org
#fra.rsync.repo.almalinux.org
[matrix_synapse]
almalinux.im ansible_host=170.249.201.58

[matrix_synapse_stg]
stg.almalinux.im

[hashivault]
vault[01:05].secrets.almalinux.org
Expand Down
8 changes: 8 additions & 0 deletions roles/mirror/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ mirror_repos:
rsync_minute: "0"
rsync_hour: "*/1"
rsync_file: almalinux_rsync

mirror_bootstrap_mirror: true
mirror_configure_crons: true

mirror_rsync_modules:
almalinux:
path: "{{ mirror_path }}/almalinux"
comment: AlmaLinux repository
7 changes: 6 additions & 1 deletion roles/mirror/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
- name: Restart caddy
ansible.builtin.systemd:
ansible.builtin.systemd_service:
name: caddy.service
state: restarted

- name: Restart rsyncd
ansible.builtin.systemd_service:
name: rsyncd.service
state: restarted
34 changes: 34 additions & 0 deletions roles/mirror/tasks/certbot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Route 53 tasks
ansible.builtin.include_tasks: route53.yml

- name: Install certbot and route53 plugin
ansible.builtin.package:
name:
- certbot
- python3-certbot-dns-route53
state: present
tags: certbot

- name: Start/enable certbot renew timer
ansible.builtin.systemd_service:
name: certbot-renew.timer
enabled: true
state: started
tags: certbot

- name: Configure certbot deploy hook
ansible.builtin.template:
src: certbot-deploy-hook.sh.j2
dest: /etc/letsencrypt/deploy-caddy.sh
mode: "0755"
tags: certbot

- name: Get certificate with certbot
args:
creates: /etc/letsencrypt/live/{{ inventory_hostname }}/fullchain.pem
ansible.builtin.shell: >
certbot certonly --dns-route53 -d {{ inventory_hostname }} -d rsync.repo.almalinux.org -m {{ certbot_email }} --agree-tos -n --force-renewal
--deploy-hook /etc/letsencrypt/deploy-caddy.sh
throttle: 1
tags: certbot skip_ansible_lint
45 changes: 45 additions & 0 deletions roles/mirror/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
---
- name: Add rsync backport repo
ansible.builtin.yum_repository:
name: backports-rsync
description: Backported rsync with extra features
file: backports-rsync
baseurl: http://repo.almalinux.org/backports/$releasever/$basearch/rsync/
enabled: true
gpgcheck: true
gpgkey: https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-$releasever

- name: Update rsync # noqa package-latest
ansible.builtin.package:
name: rsync
state: latest

- name: Install Caddy
ansible.builtin.dnf:
name: caddy
Expand Down Expand Up @@ -90,6 +105,7 @@
loop: "{{ mirror_repos }}"
tags:
- bootstrap_mirror
when: mirror_bootstrap_mirror

- name: Setup cron for mirror
ansible.builtin.cron:
Expand All @@ -103,6 +119,7 @@
loop: "{{ mirror_repos }}"
tags:
- cron
when: mirror_configure_crons

- name: Customize sysctl
ansible.posix.sysctl:
Expand All @@ -113,10 +130,38 @@
tags:
- sysctl

- name: Certbot
ansible.builtin.include_tasks: certbot.yml
when: mirror_custom_ssl

- name: Start/Enable Caddy
ansible.builtin.systemd:
name: caddy.service
state: started
enabled: true
tags:
- caddy

- name: Install rsyncd
ansible.builtin.package:
name: rsync-daemon
state: present
when: mirror_rsync_modules

- name: Configure rsyncd
ansible.builtin.template:
src: rsyncd.conf.j2
dest: /etc/rsyncd.conf
mode: "0644"
notify: Restart rsyncd
when: mirror_rsync_modules

- name: Start rsyncd
ansible.builtin.systemd_service:
name: rsyncd
enabled: true
state: started
when: mirror_rsync_modules

# TODO: correctly handle deploy-repo-alma user for tier0 mirrors
# TODO: handle keying tier0 servers accordingly to accept syncs from repo.alma
19 changes: 19 additions & 0 deletions roles/mirror/tasks/route53.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Create AWS config dir
ansible.builtin.file:
path: /root/.aws
state: directory
mode: "0700"

- name: Write AWS config file
vars:
aws_access_key_id:
"{{ lookup('community.hashi_vault.hashi_vault', 'kv/data/infra/aws/rsync.repo.almalinux.org/route53:access_key',
token=lookup('env', 'VAULT_TOKEN'), url=secrets_url) }}"
aws_secret_access_key:
"{{ lookup('community.hashi_vault.hashi_vault', 'kv/data/infra/aws/rsync.repo.almalinux.org/route53:secret_key',
token=lookup('env', 'VAULT_TOKEN'), url=secrets_url) }}"
ansible.builtin.template:
src: aws_config.j2
dest: /root/.aws/config
mode: "0600"
5 changes: 5 additions & 0 deletions roles/mirror/templates/aws_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# {{ ansible_managed }}
[default]
region = us-east-1
aws_access_key_id = {{ aws_access_key_id }}
aws_secret_access_key = {{ aws_secret_access_key}}
11 changes: 11 additions & 0 deletions roles/mirror/templates/certbot-deploy-hook.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# {{ ansible_managed }}

# dynamic based on domain. ex: /etc/letsencrypt/live/example.com
cert_dir=$RENEWED_LINEAGE

install -pD -m 700 -g caddy -o caddy $cert_dir/fullchain.pem /etc/caddy/{{ inventory_hostname }}.fullchain.pem
install -pD -m 700 -g caddy -o caddy $cert_dir/privkey.pem /etc/caddy/{{ inventory_hostname }}.privkey.pem

# only reload caddy if it is running
systemctl is-active --quiet caddy.service && systemctl reload caddy.service
5 changes: 1 addition & 4 deletions roles/mirror/templates/etc/caddy/Caddyfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

root * {{ mirror_path }}


file_server {
browse
}
Expand All @@ -15,7 +14,7 @@
}
}

{% if mirror_custom_ssl %}tls /etc/letsencrypt/live/{{ inventory_hostname }}/fullchain.pem /etc/letsencrypt/live/{{ inventory_hostname}}/privkey.pem{% endif %}
{% if mirror_custom_ssl %}tls /etc/caddy/{{ inventory_hostname }}.fullchain.pem /etc/caddy/{{ inventory_hostname}}.privkey.pem{% endif %}

}

Expand All @@ -24,7 +23,6 @@ http://{{ inventory_hostname }} {

root * {{ mirror_path }}


file_server {
browse
}
Expand All @@ -35,6 +33,5 @@ http://{{ inventory_hostname }} {
}
}


}
{% endif %}
23 changes: 23 additions & 0 deletions roles/mirror/templates/rsyncd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# {{ ansible_managed }}

uid = nobody
gid = nobody
reverse lookup = false
forward lookup = false
max connections = 1000
transfer logging = true
use chroot = true
read only = true
timeout = 600

motd file = /etc/rsyncmotd

log file=/var/log/rsyncd.log

{% for module,values in rsync_modules.items() %}
[{{ module }}]
{% for key,value in values.items() %}
{{ key }} = {{ value }}
{% endfor %}

{% endfor %}

0 comments on commit 787a647

Please sign in to comment.