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
    

  • 0 Stimmen
    1 Beiträge
    101 Aufrufe
    Niemand hat geantwortet
  • Ansible - host_key_checking

    Ansible
    1
    0 Stimmen
    1 Beiträge
    121 Aufrufe
    Niemand hat geantwortet
  • Star64 - Model A 8GB

    Hardware
    2
    0 Stimmen
    2 Beiträge
    111 Aufrufe
    FrankMF

    Der Stromanschluss ist derselbe wie beim Quartz64, somit kann ich alle meine Netzteile weiter benutzen.

  • 10G

    Linux
    2
    0 Stimmen
    2 Beiträge
    126 Aufrufe
    FrankMF

    Bedingt durch ein paar Probleme mit der Forensoftware, habe ich einen kleinen Datenverlust erlitten. Dazu gehören auch hier einige Beiträge. Dann versuche ich das mal zu rekonstruieren.

    Oben hatten wir das SFP+ Modul ja getestet. Als nächsten Schritt habe ich die ASUS XG-C100F 10G SFP+ Netzwerkkarte in meinen Hauptrechner verbaut.

    20211028_162455_ergebnis.jpg

    Die Verbindung zum Zyxel Switch erfolgt mit einem DAC-Kabel. Im Video zum Zyxel Switch wurde schön erklärt, das die DAC Verbindung stromsparender als RJ45 Adapter sind. Somit fiel die Wahl auf die DAC Verbindungen. Hier nochmal das Video.

    So sieht so ein DAC Verbindungskabel aus. Die SFP+ Adapter sind direkt daran montiert.

    20211028_170118_ergebnis.jpg

    ethtool root@frank-MS-7C37:/home/frank# ethtool enp35s0 Settings for enp35s0: Supported ports: [ FIBRE ] Supported link modes: 100baseT/Full 1000baseT/Full 10000baseT/Full 2500baseT/Full 5000baseT/Full Supported pause frame use: Symmetric Receive-only Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 100baseT/Full 1000baseT/Full 10000baseT/Full 2500baseT/Full 5000baseT/Full Advertised pause frame use: Symmetric Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 10000Mb/s Duplex: Full Port: FIBRE PHYAD: 0 Transceiver: internal Auto-negotiation: on Supports Wake-on: pg Wake-on: g Current message level: 0x00000005 (5) drv link Link detected: yes iperf3 ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Accepted connection from 192.168.3.207, port 44570 [ 5] local 192.168.3.213 port 5201 connected to 192.168.3.207 port 44572 [ ID] Interval Transfer Bitrate Retr Cwnd [ 5] 0.00-1.00 sec 1.10 GBytes 9.43 Gbits/sec 46 1.59 MBytes [ 5] 1.00-2.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.60 MBytes [ 5] 2.00-3.00 sec 1.10 GBytes 9.42 Gbits/sec 3 1.60 MBytes [ 5] 3.00-4.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.60 MBytes [ 5] 4.00-5.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.61 MBytes [ 5] 5.00-6.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.63 MBytes [ 5] 6.00-7.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.63 MBytes [ 5] 7.00-8.00 sec 1.09 GBytes 9.41 Gbits/sec 0 1.68 MBytes [ 5] 8.00-9.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.68 MBytes [ 5] 9.00-10.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.68 MBytes [ 5] 10.00-10.02 sec 22.5 MBytes 9.45 Gbits/sec 0 1.68 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.02 sec 11.0 GBytes 9.42 Gbits/sec 49 sender
  • Mainline 5.11.x

    Images
    1
    0 Stimmen
    1 Beiträge
    221 Aufrufe
    Niemand hat geantwortet
  • Kopia - Mounten einer Sicherung

    Verschoben Kopia
    1
    0 Stimmen
    1 Beiträge
    200 Aufrufe
    Niemand hat geantwortet
  • 1 Stimmen
    13 Beiträge
    1k Aufrufe
    FrankMF

    Ich möchte das dann hier zum Abschluss bringen, das NAS ist heute zusammengebaut worden. Hier zwei Fotos.

    IMG_20200425_102156_ergebnis.jpg

    IMG_20200425_102206_ergebnis.jpg

  • Proxmox - Neue HDD hinzufügen

    Verschoben Proxmox
    2
    0 Stimmen
    2 Beiträge
    3k Aufrufe
    FrankMF

    Hoppla, da passt was nicht.

    root@frank-mankel:~# pvesm status Name Type Status Total Used Available % VM lvmthin active 488136704 23284120 464852583 4.77% backup dir active 57278576 3501916 50837372 6.11% local dir active 57278576 3501916 50837372 6.11% local-lvm lvmthin active 147275776 0 147275776 0.00%

    Hier sieht man, das backup ca. 50GB groß ist. Da die Partition deutlich größer ist, fehlt da was!?? Kurz mal nachgedacht und gesucht..... 😉

    Der Eintrag in /etc/fstab muss natürlich auch vorhanden sein, so wie gewohnt. Danach

    root@frank-mankel:~# pvesm status Name Type Status Total Used Available % VM lvmthin active 488136704 23284120 464852583 4.77% backup dir active 1921797220 77856 1824027568 0.00% local dir active 57278576 3502984 50836304 6.12% local-lvm lvmthin active 147275776 0 147275776 0.00%

    e9b52dbe-dc81-4bec-a4e8-a26885f57d84-grafik.png

    Mein vorhin erstelltes Backup war weg. Also aufpassen!!