Skip to content

Commit

Permalink
router rebuild/recovery fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
solidDoWant committed Oct 27, 2023
1 parent 06287d8 commit be4418c
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
* @onedr0p
* @solidDoWant
2 changes: 1 addition & 1 deletion bootstrap/local/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jmsepath
jmespath
docker
lxml
openshift
3 changes: 2 additions & 1 deletion bootstrap/remote/inventory
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ working_dir_path="{{ repo_root_path }}/working"
k8s_masters

[k8s_masters]
10.1.1.[1:4] ansible_user="bootstrap" k3s_control_node=true k3s_use_unsupported_config=true
10.1.1.[1:2] ansible_user="bootstrap" k3s_control_node=true k3s_use_unsupported_config=true
10.1.1.4 ansible_user="bootstrap" k3s_control_node=true k3s_use_unsupported_config=true

[proxmox_hosts:children]
opnsense_hosts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
state: present
filename: pve-no-subscription
update_cache: false
- name: Add Ceph Pacific repository
- name: Remove enterprise Ceph repository
apt_repository:
repo: "deb http://download.proxmox.com/debian/ceph-pacific {{ ansible_distribution_release }} main"
repo: "deb https://enterprise.proxmox.com/debian/ceph-quincy {{ ansible_distribution_release }} enterprise"
state: absent
filename: pve-enterprise
- name: Add Ceph repository
apt_repository:
repo: "deb http://download.proxmox.com/debian/ceph-quincy {{ ansible_distribution_release }} main"
state: present
filename: ceph
update_cache: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
copy:
src: "{{ local_kubeconfig_path }}"
dest: /usr/local/etc/coredns/kubeconfig
mode: 0640
mode: "0600"
owner: root
group: wheel
register: copied_kubeconfig
Expand All @@ -14,10 +14,10 @@
dest: "/usr/local/etc/coredns/root_config.d/k8s_gateway_{{ secret_domain }}"
owner: root
group: wheel
mode: 0755
when: copied_kubeconfig.changed
mode: "0755"
register: created_coredns_config

- name: Restart CoreDNS
shell: |
/usr/local/etc/rc.d/coredns restart
when: copied_kubeconfig.changed
when: created_coredns_config.changed
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ clusters:
- name: home
cluster:
certificate-authority-data: "{{ DNSCertificateAuthority }}"
server: "https://{{ kube_vip_ip }}:6443"
server: "https://{{ kube_vip_ip }}:443"
contexts:
- name: home
context:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
coredns_working_dir_path: "{{ working_dir_path }}/coredns"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: Check if the CoreDNS binary file exists
ansible.builtin.stat:
path: "{{ coredns_working_dir_path }}/coredns"
register: coredns_binary

- name: Create the coredns directory
ansible.builtin.file:
path: "{{ coredns_working_dir_path }}"
state: directory
mode: "0755"
register: coredns_directory
when: not coredns_binary.stat.exists

# TODO version this with Renovate
- name: Get the latest k8s_gateway release data from GitHub
ansible.builtin.uri:
url: https://api.github.com/repos/ori-edge/k8s_gateway/releases/latest
method: GET
return_content: true
status_code: 200
body_format: json
register: github_k8s_gateway_page
when: not coredns_binary.stat.exists

# TODO don't hardcode OS info
- name: Download and extract the k8s_gateway version of CoreDNS from GitHub
ansible.builtin.unarchive:
src: "{{ github_k8s_gateway_page.json | json_query(query) | first }}"
dest: "{{ coredns_working_dir_path }}"
remote_src: true
include:
- coredns
vars:
query: assets[?ends_with(name, 'freebsd_amd64.tar.gz')].browser_download_url
when: not coredns_binary.stat.exists
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# PROVIDE: coredns
# REQUIRE: DAEMON NETWORKING
# REQUIRE: DAEMON NETWORKING frr
# KEYWORD: shutdown
#
# Add the following to /etc/rc.conf[.local] to enable this service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,136 +1,141 @@
---
- name: Create config directory
file:
ansible.builtin.file:
path: /usr/local/etc/coredns
state: directory
mode: 0755
mode: "0755"

- name: Create zones directory
file:
ansible.builtin.file:
path: /usr/local/etc/coredns/config.d
state: directory
mode: 0755
mode: "0755"

- name: Create root config directory
file:
ansible.builtin.file:
path: /usr/local/etc/coredns/root_config.d
state: directory
mode: 0755
mode: "0755"

- name: Create zonefiles directory
file:
ansible.builtin.file:
path: /usr/local/etc/coredns/zones
state: directory
mode: 0755
mode: "0755"

- name: Gather facts on all hosts for DNS record creation
setup: {}
ansible.builtin.setup: {}
delegate_to: "{{ item }}"
delegate_facts: true
when: hostvars[item]['ansible_default_ipv4'] is not defined
with_items: "{{ groups['all'] }}"

- name: Create Corefile
template:
ansible.builtin.template:
src: Corefile
dest: /usr/local/etc/coredns/Corefile
mode: 0755
mode: "0755"
vars:
listening_addresses: "{{ ansible_interfaces | select('match', '^(lo\\d+|vtnet1\\S*)$') | join(' ') }}"

- name: Create config files
template:
ansible.builtin.template:
src: "{{ item }}"
dest: /usr/local/etc/coredns/config.d
mode: 0755
mode: "0755"
with_fileglob:
- ../templates/config.d/*

- name: Create zone files
template:
ansible.builtin.template:
src: "{{ item }}"
dest: /usr/local/etc/coredns/zones
mode: 0755
mode: "0755"
with_fileglob:
- ../templates/zones/*

- name: Create CoreDNS rc.conf script
copy:
ansible.builtin.copy:
src: coredns-rc.conf
dest: /etc/rc.conf.d/coredns
mode: 0755
mode: "0755"

- name: Create CoreDNS rc.d script
copy:
ansible.builtin.copy:
src: coredns-rc.d
dest: /usr/local/etc/rc.d/coredns
mode: 0755
mode: "0755"

- name: Create CoreDNS action script
copy:
ansible.builtin.copy:
src: actions_coredns.conf
dest: /usr/local/opnsense/service/conf/actions.d/actions_coredns.conf
mode: 0755
mode: "0755"

- name: Create CoreDNS start up script
copy:
ansible.builtin.copy:
src: 99-coredns
dest: /usr/local/etc/rc.syshook.d/start/99-coredns
mode: 0755
mode: "0755"

- name: Create CoreDNS log rotation config
copy:
ansible.builtin.copy:
src: coredns-newsyslog.conf
dest: /etc/newsyslog.conf.d/coredns
mode: 0755
mode: "0755"

- name: Stop running CoreDNS
shell: /usr/local/etc/rc.d/coredns stop
ansible.builtin.command: /usr/local/etc/rc.d/coredns stop
ignore_errors: true
register: coredns_stop

- name: Copy CoreDNS
copy:
ansible.builtin.copy:
src: "{{ working_dir_path }}/coredns/coredns"
dest: /usr/local/sbin/coredns
mode: 0755
mode: "0755"

- name: Disable Unbound DNS
when: coredns_stop.rc != 0

block:
- name: Pull the current OPNsense config
fetch:
ansible.builtin.fetch:
src: "{{ remote_config_path }}"
dest: "{{ local_config_path }}"
flat: true
register: downloaded_config
- name: Disable Unbound
when: downloaded_config.changed
delegate_to: localhost
block:
- name: Remove /opnsense/unbound/enable
xml:
community.general.xml:
path: "{{ local_config_path }}"
xpath: /opnsense/unbound/enable
state: absent
- name: Remove /opnsense/OPNsense/unboundplus/enabled
community.general.xml:
path: "{{ local_config_path }}"
xpath: /opnsense/OPNsense/unboundplus/enabled
state: absent
- name: Remove /opnsense/OPNsense/unboundplus/service_enabled
xml:
community.general.xml:
path: "{{ local_config_path }}"
xpath: /opnsense/OPNsense/unboundplus/service_enabled
state: absent
when: downloaded_config.changed
delegate_to: localhost
- name: Copy the new OPNsense config
copy:
ansible.builtin.copy:
src: "{{ local_config_path }}"
dest: "{{ remote_config_path }}"
backup: true
register: return_config
when: downloaded_config.changed
- name: Reload OPNsense
command: "{{ item }}"
ansible.builtin.command: "{{ item }}"
with_items:
- configctl service reload all
- configctl webgui restart
when: downloaded_config.changed and return_config.changed
when: coredns_stop.rc != 0

- name: Run CoreDNS
shell: /usr/local/etc/rc.d/coredns start
ansible.builtin.command: /usr/local/etc/rc.d/coredns start
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import ./config.d/*
directory ./zones (.*) {1}
}

template ANY AAAA {
rcode NOERROR
}

forward . tls://1.1.1.1 tls://1.0.0.1 {
tls_servername cloudflare-dns.com
}
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/remote/playbooks/gateway_hosts/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
become: true

roles:
- role: coredns_builder
tags: coredns_builder
- role: coredns_downloader
tags: coredns_downloader

- hosts: opnsense
become: true
Expand Down
Loading

0 comments on commit be4418c

Please sign in to comment.