Files
convert-images-for-web/playbooks/kvm.yml

80 lines
2.0 KiB
YAML

---
- name: Create machine and set up ip
hosts: all
user: root
gather_facts: no
serial: 1
tasks:
- name: Clone VM
delegate_to: localhost
proxmox_kvm:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
clone: "{{ ubuntu_template_vm_name }}"
full: yes
name: '{{ inventory_hostname }}'
node: 'rack2'
target: '{{ hypervisor }}'
storage: 'SSD1'
format: 'qcow2'
timeout: 6000
register: cloned
- name: Wait 10 seconds for proxmox to register the new node
wait_for: timeout=10
delegate_to: localhost
when: cloned.changed
- name: Set resources
delegate_to: localhost
proxmox_kvm:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
name: '{{ inventory_hostname }}'
node: '{{ hypervisor }}'
cores: '{{ cpus }}'
memory: '{{ memory }}'
update: yes
when: cloned.changed
- name: Start VM
delegate_to: localhost
proxmox_kvm:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
name: '{{ inventory_hostname }}'
node: '{{ hypervisor }}'
state: started
when: cloned.changed
- name: Wait for connection
delegate_to: 10.0.0.211
wait_for_connection:
delay: 60
timeout: 180
when: cloned.changed
- name: Wait 120 seconds for apt
wait_for: timeout=120
delegate_to: localhost
when: cloned.changed
- include: ../roles/ansible-dependencies/tasks/main.yml
delegate_to: 10.0.0.211
when: cloned.changed
- include: ../roles/configure-interfaces/tasks/main.yml
delegate_to: 10.0.0.211
when: cloned.changed
- name: wait for connection
wait_for_connection:
delay: 60
timeout: 180
when: cloned.changed