---
- name: create resource group
  azure_rm_resourcegroup:
    name: "{{ openshift_azure_resource_group_name }}"
    location: "{{ openshift_azure_resource_location }}"
    tags:
      now: "{{ lookup('pipe', 'date +%s') }}"

- name: create vnet
  azure_rm_virtualnetwork:
    name: vnet
    resource_group: "{{ openshift_azure_resource_group_name }}"
    address_prefixes:
    - 192.168.0.0/16

- name: create subnet
  azure_rm_subnet:
    name: subnet
    resource_group: "{{ openshift_azure_resource_group_name }}"
    virtual_network: vnet
    address_prefix: 192.168.0.0/24

- name: create vm
  command: >
    az vm create
    -n vm
    -g "{{ openshift_azure_resource_group_name }}"
    --size "{{ openshift_azure_vm_size | default('Standard_D4s_v3') }}"
    --image "{{ (input_image.stdout | from_json).id }}"
    --storage-sku Premium_LRS
    --admin-username cloud-user
    --ssh-dest-key-path /home/cloud-user/.ssh/authorized_keys
    --ssh-key-value "{{ openshift_azure_vm_ssh_public_key }}"
    {% if create_args is defined %}{{ create_args }}{% endif %}
  register: vm

- name: add vm to inventory
  add_host:
    groups: nodes
    name: "{{ (vm.stdout | from_json).publicIpAddress }}"
    ansible_ssh_user: cloud-user
    ansible_become: True
