Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
creer-une-vm-avec-cloud-init.yaml 1.16 KiB
Newer Older
  • Learn to ignore specific revisions
  • Nicolas's avatar
    Nicolas committed
    - name: "Create VM from cloud images"
      hosts: <host-proxmox>
      vars:
          id: 1000
          vm_name: "template-u2304"
          vm_core: 2
          vm_ram: 512
          vm_bridge: vmbr0
          cloudimg_path: "/path/to/lunar-server-cloudimg-amd64.img"
          disk: "local"
          user: ansible
          sshkey_path: "/path/to/ssh/public_key>"
          ipconfig0: "ip=<ip-address>/<cidr>,gw=<ip-gateway>"
      tasks:
        - name: Create VM
          command: qm create {{ id }} --name {{ vm_name }} --cores {{ vm_core }} --memory {{ vm_ram }} --net0 virtio,bridge={{ vm_bridge }},firewall=1 --scsihw virtio-scsi-pci --agent 1
    
        - name: Import image
          command: qm set {{ id }} --scsi0 {{ disk }}:0,import-from={{ cloudimg_path }}
    
        - name: Set Boot Order
          command: qm set {{ id }} --boot order=scsi0
    
        - name: Add Cloudinit Disk
          command: qm set {{ id }} --ide2 {{ disk }}:cloudinit
    
        - name: Create Serial Port
          command: qm set {{ id }} --serial0 socket --vga serial0
    
        - name: Configure Cloud-init - User & Network
          shell: |
            qm set {{ id }} --ciuser {{ user }}
            qm set {{ id }} --sshkeys {{ sshkey_path }}
            qm set {{ id }} --ipconfig0 {{ ipconfig0 }}