diff options
| author | 2026-10-22 20:03:44 +0000 | |
|---|---|---|
| committer | 2026-10-22 20:03:44 +0000 | |
| commit | 4bab7edf283d1357816cbbf7a6b94e0280f1078f (patch) | |
| tree | d684b067337a35c2e26a1145c470989698330fbb | |
| download | infra-4bab7edf283d1357816cbbf7a6b94e0280f1078f.tar.gz | |
chore: setup ansible
| -rw-r--r-- | .dir-locals.el | 4 | ||||
| -rw-r--r-- | .envrc | 1 | ||||
| -rw-r--r-- | .vault_pass.gpg | bin | 0 -> 212 bytes | |||
| -rw-r--r-- | ansible.cfg | 12 | ||||
| -rwxr-xr-x | bin/vault_pass_gpg.sh | 5 | ||||
| -rw-r--r-- | group_vars/all.yml | 2 | ||||
| -rw-r--r-- | inventory.ini | 7 | ||||
| -rw-r--r-- | provision.yml | 28 | ||||
| -rw-r--r-- | roles/base/defaults/main.yml | 9 | ||||
| -rw-r--r-- | roles/base/handlers/main.yml | 5 | ||||
| -rw-r--r-- | roles/base/tasks/main.yml | 152 | ||||
| -rw-r--r-- | roles/base/templates/repositories.j2 | 4 | ||||
| -rw-r--r-- | roles/base/templates/resolv.conf.j2 | 4 | ||||
| -rw-r--r-- | roles/base/templates/sshd_config.j2 | 123 |
14 files changed, 356 insertions, 0 deletions
diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..e75fe38 --- /dev/null +++ b/.dir-locals.el | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | ;;; Directory Local Variables -*- no-byte-compile: t -*- | ||
| 2 | ;;; For more information see (info "(emacs) Directory Variables") | ||
| 3 | |||
| 4 | ((nil . ((compile-command . "ansible-playbook provision.yml")))) | ||
| @@ -0,0 +1 @@ | |||
| export ANSIBLE_CONFIG="$PWD/ansible.cfg" | |||
diff --git a/.vault_pass.gpg b/.vault_pass.gpg new file mode 100644 index 0000000..b9dd77d --- /dev/null +++ b/.vault_pass.gpg | |||
| Binary files differ | |||
diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..2f273d3 --- /dev/null +++ b/ansible.cfg | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | [defaults] | ||
| 2 | inventory = inventory.ini | ||
| 3 | roles_path = ./roles | ||
| 4 | vault_password_file = ./bin/vault_pass_gpg.sh | ||
| 5 | callback_result_format = yaml | ||
| 6 | gathering = smart | ||
| 7 | fact_caching = memory | ||
| 8 | |||
| 9 | [ssh_connection] | ||
| 10 | pipelining = True | ||
| 11 | ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=accept-new | ||
| 12 | transfer_method = smart | ||
diff --git a/bin/vault_pass_gpg.sh b/bin/vault_pass_gpg.sh new file mode 100755 index 0000000..3370ad0 --- /dev/null +++ b/bin/vault_pass_gpg.sh | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | BIN="$(cd "$(dirname "$0")" && pwd)" | ||
| 4 | |||
| 5 | exec gpg --batch --use-agent --decrypt "$BIN/../.vault_pass.gpg" | ||
diff --git a/group_vars/all.yml b/group_vars/all.yml new file mode 100644 index 0000000..e7c862b --- /dev/null +++ b/group_vars/all.yml | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | --- | ||
| 2 | ansible_managed: "Ansible managed: generated from '{{ template_fullpath | relpath(playbook_dir) }}'" | ||
diff --git a/inventory.ini b/inventory.ini new file mode 100644 index 0000000..548d840 --- /dev/null +++ b/inventory.ini | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | [alpine] | ||
| 2 | vps ansible_host=michalec.dev | ||
| 3 | |||
| 4 | [alpine:vars] | ||
| 5 | ansible_user=cmmm | ||
| 6 | ansible_python_interpreter=/usr/bin/python3 | ||
| 7 | ansible_become_method=community.general.doas | ||
diff --git a/provision.yml b/provision.yml new file mode 100644 index 0000000..ea2e5b3 --- /dev/null +++ b/provision.yml | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | --- | ||
| 2 | - name: Bootstrap Alpine Linux | ||
| 3 | hosts: alpine | ||
| 4 | gather_facts: false | ||
| 5 | become: true | ||
| 6 | |||
| 7 | tasks: | ||
| 8 | - name: Install Python 3 | ||
| 9 | ansible.builtin.raw: test -x /usr/bin/python3 || apk add --no-cache python3 | ||
| 10 | register: bootstrap_python | ||
| 11 | changed_when: bootstrap_python.stdout != "" | ||
| 12 | |||
| 13 | - name: Provision VPS | ||
| 14 | hosts: vps | ||
| 15 | become: true | ||
| 16 | roles: | ||
| 17 | - role: base | ||
| 18 | vars: | ||
| 19 | hostname: "vps" | ||
| 20 | username: "cmmm" | ||
| 21 | nameservers: | ||
| 22 | - "212.227.123.16" | ||
| 23 | - "212.227.123.17" | ||
| 24 | repositories: | ||
| 25 | - "https://dl-cdn.alpinelinux.org/alpine/edge/main" | ||
| 26 | - "https://dl-cdn.alpinelinux.org/alpine/edge/community" | ||
| 27 | - "https://dl-cdn.alpinelinux.org/alpine/edge/testing" | ||
| 28 | - "/home/cmmm/packages/testing" | ||
diff --git a/roles/base/defaults/main.yml b/roles/base/defaults/main.yml new file mode 100644 index 0000000..2f581d8 --- /dev/null +++ b/roles/base/defaults/main.yml | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | --- | ||
| 2 | repositories: | ||
| 3 | - "https://dl-cdn.alpinelinux.org/alpine/latest-stable/main" | ||
| 4 | |||
| 5 | nameservers: | ||
| 6 | - "9.9.9.9" | ||
| 7 | - "9.9.9.10" | ||
| 8 | - "1.1.1.1" | ||
| 9 | - "1.0.0.1" | ||
diff --git a/roles/base/handlers/main.yml b/roles/base/handlers/main.yml new file mode 100644 index 0000000..6998953 --- /dev/null +++ b/roles/base/handlers/main.yml | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | --- | ||
| 2 | - name: Restart sshd | ||
| 3 | ansible.builtin.service: | ||
| 4 | name: sshd | ||
| 5 | state: restarted | ||
diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml new file mode 100644 index 0000000..2fe9a88 --- /dev/null +++ b/roles/base/tasks/main.yml | |||
| @@ -0,0 +1,152 @@ | |||
| 1 | --- | ||
| 2 | - block: | ||
| 3 | - name: Configure resolv.conf | ||
| 4 | ansible.builtin.template: | ||
| 5 | src: resolv.conf.j2 | ||
| 6 | dest: /etc/resolv.conf | ||
| 7 | owner: root | ||
| 8 | group: root | ||
| 9 | mode: '0444' | ||
| 10 | |||
| 11 | - name: Configure Alpine package repositories | ||
| 12 | ansible.builtin.template: | ||
| 13 | src: repositories.j2 | ||
| 14 | dest: /etc/apk/repositories | ||
| 15 | owner: root | ||
| 16 | group: root | ||
| 17 | mode: '0444' | ||
| 18 | register: apk_repos | ||
| 19 | |||
| 20 | - name: Update apk repository cache | ||
| 21 | community.general.apk: | ||
| 22 | update_cache: true | ||
| 23 | when: apk_repos.changed | ||
| 24 | |||
| 25 | - name: Install baseline native packages via apk | ||
| 26 | community.general.apk: | ||
| 27 | name: | ||
| 28 | - ca-certificates | ||
| 29 | - curl | ||
| 30 | - wget | ||
| 31 | - git | ||
| 32 | - htop | ||
| 33 | - acl | ||
| 34 | - doas | ||
| 35 | - mosh | ||
| 36 | - zram-init | ||
| 37 | state: present | ||
| 38 | |||
| 39 | - name: Clean local Alpine package cache | ||
| 40 | ansible.builtin.command: | ||
| 41 | cmd: apk cache clean | ||
| 42 | changed_when: false | ||
| 43 | |||
| 44 | - name: Create un-privileged user for management | ||
| 45 | ansible.builtin.user: | ||
| 46 | name: "{{ username }}" | ||
| 47 | shell: /bin/ash | ||
| 48 | groups: wheel | ||
| 49 | create_home: true | ||
| 50 | |||
| 51 | - name: Configure doas without password for wheel group | ||
| 52 | ansible.builtin.copy: | ||
| 53 | content: "permit nopass :wheel\n" | ||
| 54 | dest: /etc/doas.d/wheel.conf | ||
| 55 | owner: root | ||
| 56 | group: root | ||
| 57 | mode: '0440' | ||
| 58 | |||
| 59 | - name: Deploy sshd_config | ||
| 60 | ansible.builtin.template: | ||
| 61 | src: sshd_config.j2 | ||
| 62 | dest: /etc/ssh/sshd_config | ||
| 63 | owner: root | ||
| 64 | group: root | ||
| 65 | mode: '0400' | ||
| 66 | validate: /usr/sbin/sshd -t -f %s | ||
| 67 | notify: Restart sshd | ||
| 68 | |||
| 69 | - name: Configure OpenRC sysinit services | ||
| 70 | ansible.builtin.service: | ||
| 71 | name: "{{ item }}" | ||
| 72 | enabled: true | ||
| 73 | runlevel: sysinit | ||
| 74 | loop: | ||
| 75 | - devfs | ||
| 76 | - dmesg | ||
| 77 | - hwdrivers | ||
| 78 | - mdev | ||
| 79 | |||
| 80 | - name: Configure OpenRC boot services | ||
| 81 | ansible.builtin.service: | ||
| 82 | name: "{{ item }}" | ||
| 83 | enabled: true | ||
| 84 | runlevel: boot | ||
| 85 | loop: | ||
| 86 | - bootmisc | ||
| 87 | - hostname | ||
| 88 | - hwclock | ||
| 89 | - modules | ||
| 90 | - networking | ||
| 91 | - seedrng | ||
| 92 | |||
| 93 | - name: Configure OpenRC default services and start them | ||
| 94 | ansible.builtin.service: | ||
| 95 | name: "{{ item }}" | ||
| 96 | enabled: true | ||
| 97 | state: started | ||
| 98 | loop: | ||
| 99 | - crond | ||
| 100 | - sshd | ||
| 101 | - zram-init | ||
| 102 | |||
| 103 | - name: Configure OpenRC shutdown services | ||
| 104 | ansible.builtin.service: | ||
| 105 | name: "{{ item }}" | ||
| 106 | enabled: true | ||
| 107 | runlevel: shutdown | ||
| 108 | loop: | ||
| 109 | - killprocs | ||
| 110 | - mount-ro | ||
| 111 | - savecache | ||
| 112 | |||
| 113 | - name: Ensure TCP BBR kernel module loads on boot | ||
| 114 | ansible.builtin.lineinfile: | ||
| 115 | path: /etc/modules | ||
| 116 | line: tcp_bbr | ||
| 117 | create: true | ||
| 118 | mode: '0644' | ||
| 119 | register: bbr_module | ||
| 120 | |||
| 121 | - name: Load TCP BBR module immediately if not loaded | ||
| 122 | ansible.builtin.command: | ||
| 123 | cmd: modprobe tcp_bbr | ||
| 124 | # Ensures it's active immediately | ||
| 125 | when: bbr_module.changed or ansible_facts["kernel"] is defined | ||
| 126 | |||
| 127 | - name: Enable BBR network congestion control | ||
| 128 | ansible.builtin.sysctl: | ||
| 129 | name: "{{ item.name }}" | ||
| 130 | value: "{{ item.value }}" | ||
| 131 | sysctl_set: true | ||
| 132 | state: present | ||
| 133 | reload: true | ||
| 134 | loop: | ||
| 135 | # Congestion & Queues | ||
| 136 | - { name: 'net.core.default_qdisc', value: 'fq' } | ||
| 137 | - { name: 'net.ipv4.tcp_congestion_control', value: 'bbr' } | ||
| 138 | - { name: 'net.core.somaxconn', value: '1024' } | ||
| 139 | - { name: 'net.ipv4.tcp_max_syn_backlog', value: '2048' } | ||
| 140 | # TCP Performance & Fast Open | ||
| 141 | - { name: 'net.ipv4.tcp_tw_reuse', value: '1' } | ||
| 142 | - { name: 'net.ipv4.tcp_fastopen', value: '3' } | ||
| 143 | - { name: 'net.ipv4.tcp_fin_timeout', value: '15' } | ||
| 144 | # Security Hardening | ||
| 145 | - { name: 'net.ipv4.tcp_syncookies', value: '1' } | ||
| 146 | - { name: 'net.ipv4.conf.all.rp_filter', value: '1' } | ||
| 147 | - { name: 'net.ipv4.conf.default.rp_filter', value: '1' } | ||
| 148 | - { name: 'net.ipv4.conf.all.accept_source_route', value: '0' } | ||
| 149 | - { name: 'net.ipv4.icmp_echo_ignore_broadcasts', value: '1' } | ||
| 150 | |||
| 151 | tags: | ||
| 152 | - base | ||
diff --git a/roles/base/templates/repositories.j2 b/roles/base/templates/repositories.j2 new file mode 100644 index 0000000..096e267 --- /dev/null +++ b/roles/base/templates/repositories.j2 | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | # {{ ansible_managed }} | ||
| 2 | {% for repo in repositories %} | ||
| 3 | {{ repo }} | ||
| 4 | {% endfor %} | ||
diff --git a/roles/base/templates/resolv.conf.j2 b/roles/base/templates/resolv.conf.j2 new file mode 100644 index 0000000..b3de7ba --- /dev/null +++ b/roles/base/templates/resolv.conf.j2 | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | # {{ ansible_managed }} | ||
| 2 | {% for ns in nameservers %} | ||
| 3 | nameserver {{ ns }} | ||
| 4 | {% endfor %} | ||
diff --git a/roles/base/templates/sshd_config.j2 b/roles/base/templates/sshd_config.j2 new file mode 100644 index 0000000..dc5029d --- /dev/null +++ b/roles/base/templates/sshd_config.j2 | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | # {{ ansible_managed }} | ||
| 2 | |||
| 3 | # This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin | ||
| 4 | |||
| 5 | # The strategy used for options in the default sshd_config shipped with | ||
| 6 | # OpenSSH is to specify options with their default value where | ||
| 7 | # possible, but leave them commented. Uncommented options override the | ||
| 8 | # default value. | ||
| 9 | |||
| 10 | # Include configuration snippets before processing this file to allow the | ||
| 11 | # snippets to override directives set in this file. | ||
| 12 | Include /etc/ssh/sshd_config.d/*.conf | ||
| 13 | |||
| 14 | #Port 22 | ||
| 15 | #AddressFamily any | ||
| 16 | #ListenAddress 0.0.0.0 | ||
| 17 | #ListenAddress :: | ||
| 18 | |||
| 19 | #HostKey /etc/ssh/ssh_host_rsa_key | ||
| 20 | #HostKey /etc/ssh/ssh_host_ecdsa_key | ||
| 21 | #HostKey /etc/ssh/ssh_host_ed25519_key | ||
| 22 | #HostKey /etc/ssh/ssh_host_mldsa44_ed25519_key | ||
| 23 | |||
| 24 | # Ciphers and keying | ||
| 25 | #RekeyLimit default none | ||
| 26 | |||
| 27 | # Logging | ||
| 28 | #SyslogFacility AUTH | ||
| 29 | #LogLevel INFO | ||
| 30 | |||
| 31 | # Authentication: | ||
| 32 | |||
| 33 | #LoginGraceTime 2m | ||
| 34 | PermitRootLogin no | ||
| 35 | #StrictModes yes | ||
| 36 | #MaxAuthTries 6 | ||
| 37 | #MaxSessions 10 | ||
| 38 | |||
| 39 | #PubkeyAuthentication yes | ||
| 40 | |||
| 41 | # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 | ||
| 42 | # but this is overridden so installations will only check .ssh/authorized_keys | ||
| 43 | AuthorizedKeysFile .ssh/authorized_keys | ||
| 44 | |||
| 45 | #AuthorizedPrincipalsFile none | ||
| 46 | |||
| 47 | #AuthorizedKeysCommand none | ||
| 48 | #AuthorizedKeysCommandUser nobody | ||
| 49 | |||
| 50 | # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts | ||
| 51 | #HostbasedAuthentication no | ||
| 52 | # Change to yes if you don't trust ~/.ssh/known_hosts for | ||
| 53 | # HostbasedAuthentication | ||
| 54 | #IgnoreUserKnownHosts no | ||
| 55 | # Don't read the user's ~/.rhosts and ~/.shosts files | ||
| 56 | #IgnoreRhosts yes | ||
| 57 | |||
| 58 | # To disable tunneled clear text passwords, change to "no" here! | ||
| 59 | PasswordAuthentication no | ||
| 60 | #PermitEmptyPasswords no | ||
| 61 | |||
| 62 | # Change to "no" to disable keyboard-interactive authentication. Depending on | ||
| 63 | # the system's configuration, this may involve passwords, challenge-response, | ||
| 64 | # one-time passwords or some combination of these and other methods. | ||
| 65 | KbdInteractiveAuthentication no | ||
| 66 | |||
| 67 | # Kerberos options | ||
| 68 | #KerberosAuthentication no | ||
| 69 | #KerberosOrLocalPasswd yes | ||
| 70 | #KerberosTicketCleanup yes | ||
| 71 | #KerberosGetAFSToken no | ||
| 72 | |||
| 73 | # GSSAPI options | ||
| 74 | #GSSAPIAuthentication no | ||
| 75 | #GSSAPICleanupCredentials yes | ||
| 76 | |||
| 77 | # Set this to 'yes' to enable PAM authentication, account processing, | ||
| 78 | # and session processing. If this is enabled, PAM authentication will | ||
| 79 | # be allowed through the KbdInteractiveAuthentication and | ||
| 80 | # PasswordAuthentication. Depending on your PAM configuration, | ||
| 81 | # PAM authentication via KbdInteractiveAuthentication may bypass | ||
| 82 | # the setting of "PermitRootLogin prohibit-password". | ||
| 83 | # If you just want the PAM account and session checks to run without | ||
| 84 | # PAM authentication, then enable this but set PasswordAuthentication | ||
| 85 | # and KbdInteractiveAuthentication to 'no'. | ||
| 86 | #UsePAM no | ||
| 87 | |||
| 88 | #AllowAgentForwarding yes | ||
| 89 | # Feel free to re-enable these if your use case requires them. | ||
| 90 | AllowTcpForwarding yes | ||
| 91 | GatewayPorts yes | ||
| 92 | X11Forwarding no | ||
| 93 | #X11DisplayOffset 10 | ||
| 94 | #X11UseLocalhost yes | ||
| 95 | #PermitTTY yes | ||
| 96 | #PrintMotd yes | ||
| 97 | #PrintLastLog yes | ||
| 98 | #TCPKeepAlive yes | ||
| 99 | #PermitUserEnvironment no | ||
| 100 | #Compression delayed | ||
| 101 | #ClientAliveInterval 0 | ||
| 102 | #ClientAliveCountMax 3 | ||
| 103 | #UseDNS no | ||
| 104 | #PidFile /run/sshd.pid | ||
| 105 | #MaxStartups 10:30:100 | ||
| 106 | #PermitTunnel no | ||
| 107 | #ChrootDirectory none | ||
| 108 | #VersionAddendum none | ||
| 109 | |||
| 110 | # no default banner path | ||
| 111 | #Banner none | ||
| 112 | |||
| 113 | # override default of no subsystems | ||
| 114 | Subsystem sftp internal-sftp | ||
| 115 | |||
| 116 | # Example of overriding settings on a per-user basis | ||
| 117 | #Match User anoncvs | ||
| 118 | # X11Forwarding no | ||
| 119 | # AllowTcpForwarding no | ||
| 120 | # PermitTTY no | ||
| 121 | # ForceCommand cvs server | ||
| 122 | |||
| 123 | Include /etc/ssh/sshd_config.d/andr/config | ||
