171 lines
3.9 KiB
YAML
171 lines
3.9 KiB
YAML
|
- name: Create resource group
|
||
|
azure_rm_resourcegroup:
|
||
|
name: Testing
|
||
|
location: "{{ location }}"
|
||
|
|
||
|
- name: Delete virtual machine
|
||
|
azure_rm_virtualmachine:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm002
|
||
|
state: absent
|
||
|
register: output
|
||
|
when: remove_vm
|
||
|
|
||
|
- debug: var=output
|
||
|
when: playbook_debug
|
||
|
|
||
|
- name: Create storage account
|
||
|
azure_rm_storageaccount:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testingstorageacct001
|
||
|
account_type: Standard_LRS
|
||
|
|
||
|
- name: Create virtual network
|
||
|
azure_rm_virtualnetwork:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm001
|
||
|
address_prefixes: "10.10.0.0/16"
|
||
|
|
||
|
- name: Add subnet
|
||
|
azure_rm_subnet:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm001
|
||
|
address_prefix: "10.10.0.0/24"
|
||
|
virtual_network: testvm001
|
||
|
|
||
|
- name: Create public ip
|
||
|
azure_rm_publicipaddress:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
allocation_method: Static
|
||
|
name: testvm001
|
||
|
|
||
|
- name: Create security group
|
||
|
azure_rm_securitygroup:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm001
|
||
|
|
||
|
- name: Create NIC
|
||
|
azure_rm_networkinterface:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm001
|
||
|
virtual_network: testvm001
|
||
|
subnet: testvm001
|
||
|
public_ip_name: testvm001
|
||
|
security_group: testvm001
|
||
|
|
||
|
- name: Create virtual machine
|
||
|
azure_rm_virtualmachine:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm002
|
||
|
vm_size: Standard_D1
|
||
|
storage_account: testingstorageacct001
|
||
|
storage_container: testvm001
|
||
|
storage_blob: testvm001.vhd
|
||
|
admin_username: adminuser
|
||
|
admin_password: Password123!
|
||
|
short_hostname: testvm
|
||
|
os_type: Linux
|
||
|
network_interfaces: testvm001
|
||
|
image: "{{ image }}"
|
||
|
register: output
|
||
|
|
||
|
- debug: var=output
|
||
|
when: playbook_debug
|
||
|
|
||
|
- name: Restart the virtual machine
|
||
|
azure_rm_virtualmachine:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm002
|
||
|
restarted: yes
|
||
|
register: output
|
||
|
|
||
|
- debug: var=output
|
||
|
when: playbook_debug
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- "azure_vm.powerstate in ['starting', 'running']"
|
||
|
- output.changed
|
||
|
|
||
|
- name: Deallocate the virtual machine
|
||
|
azure_rm_virtualmachine:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm002
|
||
|
allocated: no
|
||
|
register: output
|
||
|
|
||
|
- debug: var=output
|
||
|
when: playbook_debug
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- azure_vm.powerstate == 'deallocated'
|
||
|
- output.changed
|
||
|
|
||
|
- name: Start the virtual machine
|
||
|
azure_rm_virtualmachine:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm002
|
||
|
register: output
|
||
|
|
||
|
- debug: var=output
|
||
|
when: playbook_debug
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- "azure_vm.powerstate in ['starting', 'running']"
|
||
|
- output.changed
|
||
|
|
||
|
- name: Should be idempotent
|
||
|
azure_rm_virtualmachine:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm002
|
||
|
vm_size: Standard_D1
|
||
|
storage_account: testingstorageacct001
|
||
|
storage_container: testvm001
|
||
|
storage_blob: testvm001.vhd
|
||
|
admin_username: adminuser
|
||
|
admin_password: Password123!
|
||
|
short_hostname: testvm
|
||
|
os_type: Linux
|
||
|
network_interfaces: testvm001
|
||
|
image: "{{ image }}"
|
||
|
register: output
|
||
|
|
||
|
- assert:
|
||
|
that: not output.changed
|
||
|
|
||
|
- name: Delete VM
|
||
|
azure_rm_virtualmachine:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm002
|
||
|
state: absent
|
||
|
register: output
|
||
|
|
||
|
- debug: var=output
|
||
|
when: playbook_debug
|
||
|
|
||
|
- name: NIC should be gone
|
||
|
azure_rm_networkinterface_facts:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm001
|
||
|
register: output
|
||
|
|
||
|
- debug: var=output
|
||
|
when: playbook_debug
|
||
|
|
||
|
- assert:
|
||
|
that: azure_networkinterfaces | length == 0
|
||
|
|
||
|
- name: PIP should be gone
|
||
|
azure_rm_publicipaddress_facts:
|
||
|
resource_group: "{{ resource_group }}"
|
||
|
name: testvm001
|
||
|
register: output
|
||
|
|
||
|
- debug: var=output
|
||
|
when: playbook_debug
|
||
|
|
||
|
- assert:
|
||
|
that: azure_publicipaddresses | length == 0
|