- name: Deploy Azure Network and Web Servers in PerryWebLab
  hosts: localhost
  connection: local
  tasks:

    # Create Resource Group
    - name: Create Resource Group
      azure.azcollection.azure_rm_resourcegroup:
        name: PWebRG
        location: eastus

    # Create Virtual Network
    - name: Create Virtual Network
      azure.azcollection.azure_rm_virtualnetwork:
        name: PWNet01
        resource_group: PWebRG
        location: eastus
        address_prefixes: "10.0.0.0/16"

    # Create Subnet
    - name: Create Subnet
      azure.azcollection.azure_rm_subnet:
        name: WebSubnet
        resource_group: PWebRG
        virtual_network: PWNet01
        address_prefix: "10.0.1.0/24"

    # Deploy Web Server 1
    - name: Deploy Web Server 1 with Apache
      azure.azcollection.azure_rm_virtualmachine:
        name: Perryweb-Romulus
        resource_group: PWebRG
        location: eastus
        vm_size: Standard_B1s
        admin_username: azureuser
        ssh_password_enabled: false
        os_type: Linux
        image:
          offer: UbuntuServer
          publisher: Canonical
          sku: "18.04-LTS"
          version: latest
        network_interfaces:
          - name: WebNIC1
            subnet_name: WebSubnet
            virtual_network: PWNet01
        custom_data: |
          #cloud-config
          package_update: true
          packages:
            - apache2
          runcmd:
            - systemctl enable apache2
            - systemctl start apache2

    # Deploy Web Server 2
    - name: Deploy Web Server 2 with Apache
      azure.azcollection.azure_rm_virtualmachine:
        name: Perryweb-Remus
        resource_group: PWebRG
        location: eastus
        vm_size: Standard_B1s
        admin_username: azureuser
        ssh_password_enabled: false
        os_type: Linux
        image:
          offer: UbuntuServer
          publisher: Canonical
          sku: "18.04-LTS"
          version: latest
        network_interfaces:
          - name: WebNIC2
            subnet_name: WebSubnet
            virtual_network: PWNet01
        custom_data: |
          #cloud-config
          package_update: true
          packages:
            - apache2
          runcmd:
            - systemctl enable apache2
            - systemctl start apache2

    # Deploy Database Server
    - name: Deploy Database Server with MySQL
      azure.azcollection.azure_rm_virtualmachine:
        name: PW-DB
        resource_group: PWebRG
        location: eastus
        vm_size: Standard_B1s
        admin_username: azureuser
        ssh_password_enabled: false
        os_type: Linux
        image:
          offer: UbuntuServer
          publisher: Canonical
          sku: "18.04-LTS"
          version: latest
        network_interfaces:
          - name: DBNIC
            subnet_name: WebSubnet
            virtual_network: PWNet01
        custom_data: |
          #cloud-config
          package_update: true
          packages:
            - mysql-server
          runcmd:
            - systemctl enable mysql
            - systemctl start mysql