Skip to content
The Chat Archive
mixtral-8x7b-instruct-v0.1· Mistral AI Arena Human Preference 55K

create an ansible playbook to setup a homelab on ubuntu 22.04. it should: 1. setup…

  1. User

    create an ansible playbook to setup a homelab on ubuntu 22.04. it should:

    1. setup key-based ssh authentification
    2. install docker and docker compose
    3. setup the following containers through docker compose: npm sonarr radarr qbittorrent and jellyfin
    4. harden the linux distribution
  2. Assistant

    Sure! Here's an Ansible playbook that should accomplish what you're looking for. Please note that this is a basic playbook and may need to be modified to fit your specific needs.

    First, make sure you have Ansible installed on your local machine. Then, create a new file called homelab.yml and paste the following code into it:

    ---
    - hosts: all
      become: yes
      vars:
        ansible_user: your_username
        ssh_key_file: /path/to/your/ssh/key
        docker_compose_file: /path/to/your/docker-compose.yml
      tasks:
        - name: Add SSH key to authorized_keys
          ansible.posix.authorized_key:
            user: "{{ ansible_user }}"
            state: present
            key: "{{ lookup('file', '{{ ssh_key_file }}') }}"
    
        - name: Install Docker
          apt:
            name: docker.io
            state: present
    
        - name: Install Docker Compose
          curl:
            url: https://github.com/docker/compose/releases/download/1.29.2/docker-compose-{{ ansible_os_family }}-{{ ansible_architecture }}
            dest: /usr/local/bin/docker-compose
            mode: '0755'
    
        - name: Create directories for Docker Compose
          file:
            path: "{{ item }}"
            state: directory
            mode: '0755'
          with_items:
            - "{{ docker_compose_file.split('/')[-2] }}"
            - "{{ docker_compose_file.split('/')[-2] }}/config"
            - "{{ docker_compose_file.split('/')[-2] }}/data"
    
        - name: Copy Docker Compose file
          copy:
            src: "{{ docker_compose_file }}"
            dest: "/{{ docker_compose_file.split('/')[-2] }}/"
            mode: '0644'
    
        - name: Start Docker containers
          command: docker-compose -f /{{ docker_compose_file.split('/')[-2] }}/docker-compose.yml up -d
          args:
            chdir: "/{{ docker_compose_file.split('/')[-2] }}/"
    
      handlers:
        - name: Reload Docker service
          service:
            name: docker
            state: reloaded
    
    - hosts: all
      become: yes
      tasks:
        - name: Install fail2ban
          apt:
            name: fail2ban
            state: present
    
        - name: Configure fail2ban
          copy:
            src: fail2ban.conf
            dest: /etc/fail2ban/fail2ban.conf
            mode: '0644'
    
        - name: Restart fail2ban service
          service:
            name: fail2ban
            state: restarted
    
        - name: Install ufw
          apt:
            name: ufw
            state: present
    
        - name: Configure ufw
          blockinfile:
            path: /etc/ufw/before.rules
            create: yes
            block: |
              # Allow SSH
              ALLOW IN 22/tcp
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.