Skip to content

Ansible - Proxmox Server bearbeiten

Ansible
  • Aktuell habe ich durch eine Erkrankung etwas mehr Zeit für die Konsole, sodass ich angefangen habe, die Setups aller meiner Server zu vereinheitlichen. Anfangen wollte ich dazu mit meinem lokalen Proxmox. Dabei kam mir wieder in den Sinn, das ich auch noch ein Debian Bookworm 12 Template brauchte.

    Also, das aktuelle Debian Image heruntergeladen. Mit diesem dann einen Debian Bookworm 12 Server aufgesetzt. Jetzt brauchte ich zu diesem Zeitpunkt einen Zugang mit SSH-Key (für mein Semaphore).

    Also habe ich schon mal zwei SSH-Keys eingefügt. Einmal meinen Haupt-PC und einmal den Semaphore Server. Danach den Server in ein Template umgewandelt.

    c552d99f-4aa1-480a-a4a1-c9ac711f24fb-grafik.png

    105 ist das Template, 106 ein damit erstellter Test-Server. Ok, das läuft wie erwartet, jetzt möchte ich den Server durch konfigurieren, so wie ich das gerne haben möchte. Da es hier um Ansible geht, brauche ich dazu ein Playbook.

    ---
    ###############################################
    # Playbook for my Proxmox VMs
    ###############################################
    - name: My task
      hosts: proxmox_test
      tasks:
    
        #####################
        # Update && Upgrade installed packages and install a set of base software
        #####################
        - name: Update apt package cache.
          ansible.builtin.apt:
            update_cache: yes
            cache_valid_time: 600
    
        - name: Upgrade installed apt packages.
          ansible.builtin.apt:
            upgrade: 'yes'
    
        - name: Ensure that a base set of software packages are installed.
          ansible.builtin.apt:
            pkg:
             - crowdsec
             - crowdsec-firewall-bouncer
             - duf
             - htop
             - needrestart
             - psmisc
             - python3-openssl
             - ufw
            state: latest
    
        #####################
        # Setup UFW
        #####################
        - name: Enable UFW
          community.general.ufw:
            state: enabled
    
        - name: Set policy IN
          community.general.ufw:
            direction: incoming
            policy: deny
    
        - name: Set policy OUT
          community.general.ufw:
            direction: outgoing
            policy: allow
    
        - name: Set logging
          community.general.ufw:
            logging: 'on'
    
        - name: Allow OpenSSH rule
          community.general.ufw:
            rule: allow
            name: OpenSSH
    
        - name: Allow HTTP rule
          community.general.ufw:
            rule: allow
            port: 80
            proto: tcp
    
        - name: Allow HTTPS rule
          community.general.ufw:
            rule: allow
            port: 443
            proto: tcp
    
        #####################
        # Setup CrowdSEC
        #####################
        - name: Add one line to crowdsec config.yaml
          ansible.builtin.lineinfile:
            path: /etc/crowdsec/config.yaml
            #search_string: '<FilesMatch ".php[45]?$">'
            insertafter: '^db_config:'
            line: '  use_wal: true'
    
        #####################
        # Generate Self-Signed SSL Certificate
        # for this we need python3-openssl on the client
        #####################
        - name: Create a new directory www at given path
          ansible.builtin.file:
            path: /etc/ssl/self-signed_ssl/
            state: directory
            mode: '0755'
    
        - name: Create private key (RSA, 4096 bits)
          community.crypto.openssl_privatekey:
            path: /etc/ssl/self-signed_ssl/privkey.pem
    
        - name: Create simple self-signed certificate
          community.crypto.x509_certificate:
            path: /etc/ssl/self-signed_ssl/fullchain.pem
            privatekey_path: /etc/ssl/self-signed_ssl/privkey.pem
            provider: selfsigned
    
        - name: Check if the private key exists
          stat:
            path: /etc/ssl/self-signed_ssl/privkey.pem
          register: privkey_stat
    
        - name: Renew self-signed certificate
          community.crypto.x509_certificate:
            path: /etc/ssl/self-signed_ssl/fullchain.pem
            privatekey_path: /etc/ssl/self-signed_ssl/privkey.pem
            provider: selfsigned
          when: privkey_stat.stat.exists and privkey_stat.stat.size > 0
    
        #####################
        # Check for new kernel and reboot
        #####################
        - name: Check if a new kernel is available
          ansible.builtin.command: needrestart -k -p > /dev/null; echo $?
          register: result
          ignore_errors: yes
    
        - name: Restart the server if new kernel is available
          ansible.builtin.command: reboot
          when: result.rc == 2
          async: 1
          poll: 0
    
        - name: Wait for the reboot and reconnect
          wait_for:
            port: 22
            host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
            search_regex: OpenSSH
            delay: 10
            timeout: 60
          connection: local
    
        - name: Check the Uptime of the servers
          shell: "uptime"
          register: Uptime
    
        - debug: var=Uptime.stdout
    

    In dem Inventory muss der Server drin sein, den man bearbeiten möchte. Also, so was

    [proxmox_test]
    192.168.3.19 # BookwormTEST
    

    Playbook

    • Wir aktualisieren alle Pakete
    • Wir installieren, von mir festgelegte Pakete
    • Konfiguration UFW
    • Konfiguration CrowdSec
    • Konfiguration selbst signiertes Zertifikat
    • Kontrolle ob neuer Kernel vorhanden ist, wenn ja Reboot
    • Uptime - Kontrolle ob Server erfolgreich gestartet ist

    Danach ist der Server so, wie ich ihn gerne hätte.

    • Aktuell
    • ufw - Port 22, 80 und 443 auf (SSH, HTTP & HTTPS)
    • CrowdSec als fail2ban Ersatz
    • Selbst signierte Zertifikate benutze ich nur für lokale Server

    Die erfolgreiche Ausgabe in Semaphore, sieht so aus.

     12:38:16 PM
    Task 384 added to queue
    12:38:21 PM
    Preparing: 384
    12:38:21 PM
    Prepare TaskRunner with template: Proxmox configure Proxmox Template
    12:38:22 PM
    Von https://gitlab.com/Bullet64/playbook
    12:38:22 PM
    e7c8531..c547cfc master -> origin/master
    12:38:22 PM
    Updating Repository https://gitlab.com/Bullet64/playbook.git
    12:38:23 PM
    Von https://gitlab.com/Bullet64/playbook
    12:38:23 PM
    * branch master -> FETCH_HEAD
    12:38:23 PM
    Aktualisiere e7c8531..c547cfc
    12:38:23 PM
    Fast-forward
    12:38:23 PM
    proxmox_template_configuration.yml | 5 +++++
    12:38:23 PM
    1 file changed, 5 insertions(+)
    12:38:23 PM
    Get current commit hash
    12:38:23 PM
    Get current commit message
    12:38:23 PM
    installing static inventory
    12:38:23 PM
    No collections/requirements.yml file found. Skip galaxy install process.
    12:38:23 PM
    No roles/requirements.yml file found. Skip galaxy install process.
    12:38:26 PM
    Started: 384
    12:38:26 PM
    Run TaskRunner with template: Proxmox configure Proxmox Template
    12:38:26 PM
    12:38:26 PM
    PLAY [My task] *****************************************************************
    12:38:26 PM
    12:38:26 PM
    TASK [Gathering Facts] *********************************************************
    12:38:28 PM
    ok: [192.168.3.19]
    12:38:28 PM
    12:38:28 PM
    TASK [Update apt package cache.] ***********************************************
    12:38:29 PM
    ok: [192.168.3.19]
    12:38:29 PM
    12:38:29 PM
    TASK [Upgrade installed apt packages.] *****************************************
    12:38:30 PM
    ok: [192.168.3.19]
    12:38:30 PM
    12:38:30 PM
    TASK [Ensure that a base set of software packages are installed.] **************
    12:38:31 PM
    ok: [192.168.3.19]
    12:38:31 PM
    12:38:31 PM
    TASK [Enable UFW] **************************************************************
    12:38:32 PM
    ok: [192.168.3.19]
    12:38:32 PM
    12:38:32 PM
    TASK [Set policy IN] ***********************************************************
    12:38:34 PM
    ok: [192.168.3.19]
    12:38:34 PM
    12:38:34 PM
    TASK [Set policy OUT] **********************************************************
    12:38:36 PM
    ok: [192.168.3.19]
    12:38:36 PM
    12:38:36 PM
    TASK [Set logging] *************************************************************
    12:38:37 PM
    ok: [192.168.3.19]
    12:38:37 PM
    12:38:37 PM
    TASK [Allow OpenSSH rule] ******************************************************
    12:38:37 PM
    ok: [192.168.3.19]
    12:38:37 PM
    12:38:37 PM
    TASK [Allow HTTP rule] *********************************************************
    12:38:38 PM
    ok: [192.168.3.19]
    12:38:38 PM
    12:38:38 PM
    TASK [Allow HTTPS rule] ********************************************************
    12:38:38 PM
    ok: [192.168.3.19]
    12:38:38 PM
    12:38:38 PM
    TASK [Add one line to crowdsec config.yaml] ************************************
    12:38:39 PM
    ok: [192.168.3.19]
    12:38:39 PM
    12:38:39 PM
    TASK [Create a new directory www at given path] ********************************
    12:38:39 PM
    ok: [192.168.3.19]
    12:38:39 PM
    12:38:39 PM
    TASK [Create private key (RSA, 4096 bits)] *************************************
    12:38:41 PM
    ok: [192.168.3.19]
    12:38:41 PM
    12:38:41 PM
    TASK [Create simple self-signed certificate] ***********************************
    12:38:43 PM
    ok: [192.168.3.19]
    12:38:43 PM
    12:38:43 PM
    TASK [Check if the private key exists] *****************************************
    12:38:43 PM
    ok: [192.168.3.19]
    12:38:43 PM
    12:38:43 PM
    TASK [Renew self-signed certificate] *******************************************
    12:38:44 PM
    ok: [192.168.3.19]
    12:38:44 PM
    12:38:44 PM
    TASK [Check if a new kernel is available] **************************************
    12:38:44 PM
    changed: [192.168.3.19]
    12:38:44 PM
    12:38:44 PM
    TASK [Restart the server if new kernel is available] ***************************
    12:38:44 PM
    skipping: [192.168.3.19]
    12:38:44 PM
    12:38:44 PM
    TASK [Wait for the reboot and reconnect] ***************************************
    12:38:55 PM
    ok: [192.168.3.19]
    12:38:55 PM
    12:38:55 PM
    TASK [Check the Uptime of the servers] *****************************************
    12:38:55 PM
    changed: [192.168.3.19]
    12:38:55 PM
    12:38:55 PM
    TASK [debug] *******************************************************************
    12:38:55 PM
    ok: [192.168.3.19] => {
    12:38:55 PM
    "Uptime.stdout": " 12:38:55 up 19 min, 2 users, load average: 0,84, 0,29, 0,10"
    12:38:55 PM
    }
    12:38:55 PM
    12:38:55 PM
    PLAY RECAP *********************************************************************
    12:38:55 PM
    192.168.3.19 : ok=21 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
    12:38:55 PM
    
  • Redis ConnectionPool

    Redis
    2
    0 Stimmen
    2 Beiträge
    233 Aufrufe
    FrankMF
    Die Antwort von ChatGPT wie der Redis ConnectionPool funktioniert. Ein paar Dinge finde ich komisch. https://chat.openai.com/share/b10fdadc-2c9b-404a-bc99-c883d110d6af
  • Ansible - Hetzner Server erstellen

    Verschoben Ansible
    1
    3
    0 Stimmen
    1 Beiträge
    281 Aufrufe
    Niemand hat geantwortet
  • Proxmox - Umzug auf neue Hardware ASRock N100DC-ITX

    Angeheftet Proxmox
    25
    2
    0 Stimmen
    25 Beiträge
    5k Aufrufe
    FrankMF
    Hallo @wooshell , erst mal sehr schade das Du so einen Stress mit dem Board hast. Ich habe das jetzt schon Monate laufen, übrigens ohne einen Kühler. Ok, wird ordentlich warm aber ich hasse Lüfter Ich kann leider nicht so richtig erkennen, wo dein Problem liegt. Wie groß ist dein Speicher? Ist der in der Liste der unterstützen RAM Riegel? Das habe ich verbaut. RAM: Corsair Vengeance SODIMM 32GB (2x16GB) DDR4 2400MHz CL16 https://www.corsair.com/de/de/Kategorien/Produkte/Arbeitsspeicher/VENGEANCE-DDR4-SODIMM/p/CMSX32GX4M2A2400C16 Aus dem Bauch heraus, würde ich auf RAM tippen.
  • Debian 12 Bookworm released

    Linux
    5
    0 Stimmen
    5 Beiträge
    346 Aufrufe
    FrankMF
    Mein persönliches Fazit, alles läuft rund mit Debian Bookworm 12 Alle meine Hetzner VMs sind jetzt auf Bookworm Ok, was schwer und zeitaufwendig war, war die Nextcloud Installation bzw. der ganze PHP-Server. Das ist echt jedes mal eine Herausforderung, aber auch dabei werde ich die letzten Jahre sicherer. Hier die Story zum Nextcloud Server https://linux-nerds.org/topic/1437/nextcloud-upgrade-auf-bookworm-12 Richtig rund lief das Upgrade des NodeBB-Servers, war einfach und direkt auf Node18 hochgezogen. https://linux-nerds.org/topic/1444/nodebb-upgrade-auf-debian-bookworm-12 Damit ist jetzt alles hier auf Debian Bookworm 12 Haupt-PC VMs bei Hetzner VMs in der Proxmox Oh, da fällt mir gerade ein, der Proxmox ist noch fällig. Aber, dazu habe ich mir was einfallen lassen, da ist noch ein neues Mainboard unterwegs und dann gibt es dazu einen etwas größeren Beitrag. Danke Debian-Team, Debian Bookworm 12 ist eine runde Sache! Spannend wird jetzt, wie lange ich auf meinem Haupt-PC (Bookworm, KDE, Wayland) bleibe. Ich habe da so eine unangenehme Eigenschaft, wenn es um veraltete Pakete geht. Diesmal werde ich dann wahrscheinlich auf den Debian Unstable Zweig (sid) wechseln. Aber das dürfte noch was dauern, da ja aktuell erst mal alles passt.
  • Manjaro KDE Plasma 21.2.2

    Linux
    5
    2
    0 Stimmen
    5 Beiträge
    208 Aufrufe
    FrankMF
    Ok, geht nicht. Manjaro und ich werden leider keine Freunde. Da sind zu viele Dinge, die nicht besonders gut umgesetzt sind. Heute mal den Test gemacht und mein geliebtes Linux Mint Cinnamon installiert. Passwort für die Verschlüsselung nimmt anstandslos deutsche Sonderzeichen an WiFi geht auch nicht mit WPA3, man kann aber einfach auf WPA2 umstellen und das funktioniert. Damit endet dieser Versuch jetzt..
  • Kopia - HTTP/S Server aufsetzen

    Angeheftet Kopia
    1
    0 Stimmen
    1 Beiträge
    460 Aufrufe
    Niemand hat geantwortet
  • Rest-Server

    Verschoben Restic
    8
    0 Stimmen
    8 Beiträge
    627 Aufrufe
    FrankMF
    Dann mal eben ausprobiert. Auf meinem Server war die Version 0.9.7 selber, mit go, gebaut. Dann mache ich das auch mit der v0.10.0 so. Aber bevor ich anfange, wird die v0.9.7 gesichert. mv /usr/local/bin/rest-server /usr/local/bin/rest-server_0_9_7 So erspare ich mir im Problemfall das selber bauen. Ok, dann die neue Version bauen. git clone https://github.com/restic/rest-server.git cd rest-server go run build.go Danach befindet sich im Verzeichnis die Binärdatei rest-server Die kopieren wir jetzt cp rest-server /usr/local/bin Danach kurzer Test # rest-server --version rest-server 0.10.0 (v0.10.0-6-g037fe06) compiled with go1.11.6 on linux/amd64 Gut Version passt Dann ein Backup gestartet. Das sichert einen Teil meines Home-Verzeichnis Files: 153 new, 100 changed, 177857 unmodified Dirs: 0 new, 1 changed, 0 unmodified Added to the repo: 81.881 MiB processed 178110 files, 80.571 GiB in 0:28 snapshot 607e0027 saved Applying Policy: keep the last 3 snapshots, 3 monthly snapshots keep 5 snapshots: ID Time Host Tags Reasons Paths --------------------------------------------------------------------------------------- fa97890e 2020-07-25 21:02:05 frank-XXX monthly snapshot /home/frank 5b073bbb 2020-08-30 10:17:27 frank-XXX monthly snapshot /home/frank f7cf37ef 2020-09-06 15:13:03 frank-XXX last snapshot /home/frank 0157462c 2020-09-13 13:32:12 frank-XXX last snapshot /home/frank 607e0027 2020-09-14 08:09:34 frank-XXX last snapshot /home/frank monthly snapshot --------------------------------------------------------------------------------------- 5 snapshots remove 1 snapshots: ID Time Host Tags Paths --------------------------------------------------------------------- 3010b7cc 2020-09-06 11:39:27 frank-XXX /home/frank --------------------------------------------------------------------- 1 snapshots 1 snapshots have been removed, running prune counting files in repo building new index for repo [1:34] 100.00% 17351 / 17351 packs So weit funktioniert das genau wie vorher. Im Changelog stand ja was von Subfoldern. Das betrifft mich nicht, weil ich für jeden User genau ein Verzeichnis habe. So mit alles Gut Dann warte ich mal morgen ab, ob die täglichen Backups der Server rund laufen.
  • SSH Login ohne Passwort

    Angeheftet Linux
    4
    0 Stimmen
    4 Beiträge
    1k Aufrufe
    FrankMF
    Wie ihr ja wisst, benutze ich das Forum hier auch gerne als Notizbuch Also mal wieder was hier notieren. Mein Windows Systemadmin sagte mir heute, das es auch folgendes gibt # ssh-keygen -t ed25519 Generating public/private ed25519 key pair. Enter file in which to save the key (/root/.ssh/id_ed25519): /tmp/ed Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /tmp/ed Your public key has been saved in /tmp/ed.pub The key fingerprint is: SHA256:D33HCTW7Dy0p5kQdFTkPudx1PQh0EHFgkBvxy8KwhGM root@frank-ms7c92 The key's randomart image is: +--[ED25519 256]--+ | o=O*o=+=| | . oo o+oB+| | E o o.o.o+*| | . o +o...oo=o| | .So.o= O .| | o.= o + | | . . .| | | | | +----[SHA256]-----+ Der Key liegt nur in /tmp kopieren lohnt also nicht Ob das jetzt die Zukunft ist, kann ich nicht beantworten. Ich wollte es aber hier mal festhalten, weil es wohl mittlerweile auch von vielen Projekten benutzt wird. https://en.wikipedia.org/wiki/Ssh-keygen