From e3dd7efb8a11c3ef86677c4d7a7492908fa1453b Mon Sep 17 00:00:00 2001 From: jaydee Date: Tue, 26 May 2026 23:26:16 +0200 Subject: [PATCH] build-all --- roles/fix_router/README.md | 38 +++++++++ roles/fix_router/defaults/main.yml | 3 + roles/fix_router/files/haproxy.cfg | 50 +++++++++++ roles/fix_router/handlers/main.yml | 3 + roles/fix_router/meta/main.yml | 35 ++++++++ roles/fix_router/tasks/main.yml | 129 +++++++++++++++++++++++++++++ roles/fix_router/tests/inventory | 3 + roles/fix_router/tests/test.yml | 6 ++ roles/fix_router/vars/main.yml | 3 + 9 files changed, 270 insertions(+) create mode 100644 roles/fix_router/README.md create mode 100644 roles/fix_router/defaults/main.yml create mode 100644 roles/fix_router/files/haproxy.cfg create mode 100644 roles/fix_router/handlers/main.yml create mode 100644 roles/fix_router/meta/main.yml create mode 100644 roles/fix_router/tasks/main.yml create mode 100644 roles/fix_router/tests/inventory create mode 100644 roles/fix_router/tests/test.yml create mode 100644 roles/fix_router/vars/main.yml diff --git a/roles/fix_router/README.md b/roles/fix_router/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/fix_router/README.md @@ -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). diff --git a/roles/fix_router/defaults/main.yml b/roles/fix_router/defaults/main.yml new file mode 100644 index 0000000..8077631 --- /dev/null +++ b/roles/fix_router/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for roles/fix_router diff --git a/roles/fix_router/files/haproxy.cfg b/roles/fix_router/files/haproxy.cfg new file mode 100644 index 0000000..caffa8e --- /dev/null +++ b/roles/fix_router/files/haproxy.cfg @@ -0,0 +1,50 @@ +global + log /dev/log local0 + log /dev/log local1 notice + chroot /var/lib/haproxy + stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners + stats timeout 30s + user haproxy + group haproxy + daemon + + # Default SSL material locations + ca-base /etc/ssl/certs + crt-base /etc/ssl/private + + # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate + ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 + ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 + ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets + +defaults + log global + mode http + option httplog + option dontlognull + timeout connect 5000 + timeout client 50000 + timeout server 50000 + errorfile 400 /etc/haproxy/errors/400.http + errorfile 403 /etc/haproxy/errors/403.http + errorfile 408 /etc/haproxy/errors/408.http + errorfile 500 /etc/haproxy/errors/500.http + errorfile 502 /etc/haproxy/errors/502.http + errorfile 503 /etc/haproxy/errors/503.http + errorfile 504 /etc/haproxy/errors/504.http + +frontend vault_api + bind *:8205 + mode http + + default_backend vault_nodes + +backend vault_nodes + mode http + option httpchk GET /v1/sys/health + + http-check expect rstatus (200|429) + + server router.home.lan 192.168.77.1:8200 check + server m-server.home.lan 192.168.77.101:8200 check + server rpi5.home.lan 192.168.77.238:8200 check diff --git a/roles/fix_router/handlers/main.yml b/roles/fix_router/handlers/main.yml new file mode 100644 index 0000000..e08d607 --- /dev/null +++ b/roles/fix_router/handlers/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for roles/fix_router diff --git a/roles/fix_router/meta/main.yml b/roles/fix_router/meta/main.yml new file mode 100644 index 0000000..6f91fd3 --- /dev/null +++ b/roles/fix_router/meta/main.yml @@ -0,0 +1,35 @@ +#SPDX-License-Identifier: MIT-0 +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.2 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + 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. diff --git a/roles/fix_router/tasks/main.yml b/roles/fix_router/tasks/main.yml new file mode 100644 index 0000000..c2f1e6a --- /dev/null +++ b/roles/fix_router/tasks/main.yml @@ -0,0 +1,129 @@ +--- +- name: Setup router + become: "{{ false if inventory_hostname == 'nas.home.lan' else true }}" + block: + - name: Ensure required packages are installed + ansible.builtin.apt: + name: + - gpg + - wget + - haproxy + state: present + update_cache: true + + - name: Download HashiCorp GPG key + ansible.builtin.get_url: + url: https://apt.releases.hashicorp.com/gpg + dest: /tmp/hashicorp.asc + mode: '0644' + + - name: Convert HashiCorp GPG key to keyring format + ansible.builtin.command: + cmd: > + gpg --dearmor + -o /usr/share/keyrings/hashicorp-archive-keyring.gpg + /tmp/hashicorp.asc + args: + creates: /usr/share/keyrings/hashicorp-archive-keyring.gpg + + - name: Add HashiCorp APT repository + ansible.builtin.apt_repository: + repo: > + deb [arch={{ ansible_architecture == 'x86_64' | ternary('amd64', ansible_architecture) }} + signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] + https://apt.releases.hashicorp.com + {{ ansible_distribution_release }} + main + filename: hashicorp + state: present + + - name: Install Vault + ansible.builtin.apt: + name: vault + state: present + update_cache: true + + - name: Create service for vault agent + ansible.builtin.copy: + dest: /etc/vault.d/vault.hcl + content: | + disable_mlock = true + + storage "raft" { + path = "/opt/vault/raft" + node_id = "router.home.lan" + } + + listener "tcp" { + address = "192.168.77.1:8200" + cluster_address = "192.168.77.1:8201" + tls_disable = 1 + } + + api_addr = "http://192.168.77.1:8200" + cluster_addr = "http://192.168.77.1:8201" + ui = true + + owner: vault + group: vault + mode: '0600' + + - name: Create script for vault agent + ansible.builtin.copy: + dest: /opt/vault/scripts/unseal.sh + content: | + #!/usr/bin/env bash + export VAULT_ADDR="http://127.0.0.1:8200" + SEALED=$(vault status -format=json | jq -r .sealed) + + if [ "$SEALED" = "true" ]; then + + vault operator unseal "9990cbc17ae3b9282353ab3c6b5c5ce106d50958595189a8b8abbe924d76e2b591" + vault operator unseal "b8ef64c04bd6d2274a4fad34537d88a19ef02bbd1e858b28f6a9acf4693f7768e2" + vault operator unseal "9c735aa77d71f2c03d4b782bb6b6b3be0d0d44c99c7b72d5df77e4b1e15e7a4576" + else + echo "Vault already unsealed" + fi + + + owner: vault + group: vault + mode: '0700' + + - name: Create service + ansible.builtin.copy: + dest: /etc/systemd/system/vault-unseal.service + content: | + [Unit] + Description=Vault Docker Auto Unseal + After=vault.service + Requires=vault.service + + [Service] + Type=oneshot + ExecStart=/opt/vault/scripts/unseal.sh + RemainAfterExit=yes + + [Install] + WantedBy=multi-user.target + owner: root + group: root + mode: '0644' + + - name: Configure haproxy + ansible.builtin.copy: + dest: /etc/haproxy/haproxy.cfg + src: haproxy.cfg + owner: root + group: root + mode: '0644' + + - name: Enable and start services + ansible.builtin.systemd: + name: "{{ item }}" + enabled: yes + state: started + loop: + - vault + - vault-unseal + - haproxy \ No newline at end of file diff --git a/roles/fix_router/tests/inventory b/roles/fix_router/tests/inventory new file mode 100644 index 0000000..03ca42f --- /dev/null +++ b/roles/fix_router/tests/inventory @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +localhost + diff --git a/roles/fix_router/tests/test.yml b/roles/fix_router/tests/test.yml new file mode 100644 index 0000000..83129ba --- /dev/null +++ b/roles/fix_router/tests/test.yml @@ -0,0 +1,6 @@ +#SPDX-License-Identifier: MIT-0 +--- +- hosts: localhost + remote_user: root + roles: + - roles/fix_router diff --git a/roles/fix_router/vars/main.yml b/roles/fix_router/vars/main.yml new file mode 100644 index 0000000..0214483 --- /dev/null +++ b/roles/fix_router/vars/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for roles/fix_router