Ansible playbook Mikrotik CHR install

# Justin Miller, blog2020@dynstatic.net

# ansible-playbook -i ip, CHR-ProxMox-installation.yml -u root
# This assumes you have public key access setup

---
- hosts: all
  become: true
  vars:
    ros_version: "6.47.8"
    proxmox_vmid: "175"
    proxmox_target_storage: "local-zfs"
    proxmox_vm_storage_size: "256M"

  tasks:

    - name: Install unzip
      apt:
        name: unzip
        state: latest

    - name: Downloading CHR {{ ros_version }} image file
      unarchive:
        src: "https://download.mikrotik.com/routeros/{{ ros_version }}/chr-{{ ros_version }}.img.zip"
        dest: "/var/lib/vz/images"
        remote_src: yes
        mode: '0440'

    - name: Create vmid {{ proxmox_vmid }}
      shell: qm create {{ proxmox_vmid }} --name chr-{{ proxmox_vmid }} --net0 virtio,bridge=vmbr0 --agent 1 --memory 256 --onboot no --ostype l26 --sockets 1 --cores 1

    - name: Import CHR {{ ros_version }} to vmid {{ proxmox_vmid }}
      shell: qm importdisk {{ proxmox_vmid }} /var/lib/vz/images/chr-{{ ros_version }}.img {{ proxmox_target_storage }} --format raw

    - name: Attach CHR {{ ros_version }} to vmid {{ proxmox_vmid }}
      shell: qm set {{ proxmox_vmid }} --virtio0 {{ proxmox_target_storage }}:vm-{{ proxmox_vmid }}-disk-0

    - name: Resize disk to {{ proxmox_vm_storage_size }}
      shell: qm resize "{{ proxmox_vmid }}" virtio0 "{{ proxmox_vm_storage_size }}"

    - name: Set boot device on vmid {{ proxmox_vmid }}
      shell: qm set {{ proxmox_vmid }} --boot c --bootdisk virtio0

Leave a Reply

Your email address will not be published. Required fields are marked *

*