mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Migrate roles from ansible/azure-testing (#28074)
* Migrate roles from ansible/azure-testing as-is. * Fix yamllint issues. * Remove unused binary file.
This commit is contained in:
parent
8b92369678
commit
c27ebfc368
15 changed files with 1922 additions and 0 deletions
27
test/integration/roles/azure_rm_deployment/tasks/main.yml
Normal file
27
test/integration/roles/azure_rm_deployment/tasks/main.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
- name: Create Azure Deploy
|
||||
azure_rm_deployment:
|
||||
resource_group: Test_Deployment
|
||||
template_link: 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-simple-linux/azuredeploy.json'
|
||||
parameters:
|
||||
adminUsername:
|
||||
value: chouseknecht
|
||||
adminPassword:
|
||||
value: password123!
|
||||
dnsLabelPrefix:
|
||||
value: testvm9910001
|
||||
ubuntuOSVersion:
|
||||
value: "14.04.2-LTS"
|
||||
# debug: "{{ playbook_debug }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Add new instance to host group
|
||||
add_host:
|
||||
hostname: "{{ item.vm_name }}"
|
||||
ansible_host: "{{ item['ips'][0].public_ip }}"
|
||||
ansible_user: chouseknecht
|
||||
ansible_ssh_pass: password123!
|
||||
groupname: azure_vms
|
||||
with_items: "{{ output.deployment.instances }}"
|
427
test/integration/roles/azure_rm_networkinterface/tasks/main.yml
Normal file
427
test/integration/roles/azure_rm_networkinterface/tasks/main.yml
Normal file
|
@ -0,0 +1,427 @@
|
|||
- name: Create resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
location: "{{ location }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create virtual network
|
||||
azure_rm_virtualnetwork:
|
||||
name: vnet001
|
||||
resource_group: "{{ resource_group }}"
|
||||
address_prefixes_cidr: "10.10.0.0/16"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create subnet
|
||||
azure_rm_subnet:
|
||||
name: subnet001
|
||||
resource_group: "{{ resource_group }}"
|
||||
virtual_network_name: vnet001
|
||||
address_prefix_cidr: "10.10.0.0/24"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create second virtual network
|
||||
azure_rm_virtualnetwork:
|
||||
name: vnet002
|
||||
resource_group: "{{ resource_group }}"
|
||||
address_prefixes_cidr: "10.20.0.0/16"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create second subnet
|
||||
azure_rm_subnet:
|
||||
name: subnet002
|
||||
resource_group: "{{ resource_group }}"
|
||||
virtual_network_name: vnet002
|
||||
address_prefix_cidr: "10.20.0.0/24"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create security group
|
||||
azure_rm_securitygroup:
|
||||
name: secgroup001
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create second security group
|
||||
azure_rm_securitygroup:
|
||||
name: secgroup002
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create a public ip
|
||||
azure_rm_publicipaddress:
|
||||
name: publicip001
|
||||
resource_group: "{{ resource_group }}"
|
||||
allocation_method: "Static"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create second public ip
|
||||
azure_rm_publicipaddress:
|
||||
name: publicip002
|
||||
resource_group: "{{ resource_group }}"
|
||||
allocation_method: "Static"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Delete network interface, if it exists
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Should require subnet when creating nic
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
virtual_network_name: vnet001
|
||||
security_group_name: secgroup001
|
||||
public_ip_address_name: publicip001
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.failed
|
||||
- "'subnet' in output.msg"
|
||||
|
||||
- name: Should require virtual network when creating nic
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
security_group_name: secgroup001
|
||||
public_ip_address_name: publicip001
|
||||
subnet: subnet001
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.failed
|
||||
- "'virtual_network_name' in output.msg"
|
||||
|
||||
- name: Create nic
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
virtual_network_name: vnet001
|
||||
subnet: subnet001
|
||||
security_group_name: secgroup001
|
||||
public_ip_address_name: publicip001
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Should be idempotent
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
virtual_network_name: vnet001
|
||||
subnet: subnet001
|
||||
security_group_name: secgroup001
|
||||
public_ip_address_name: publicip001
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: not output.changed
|
||||
|
||||
- name: Should change private IP address
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
private_ip_address: 10.10.0.10
|
||||
private_ip_allocation_method: Static
|
||||
virtual_network_name: vnet001
|
||||
subnet: subnet001
|
||||
security_group_name: secgroup001
|
||||
public_ip_address_name: publicip001
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.ip_configuration.private_ip_address == '10.10.0.10'
|
||||
- output.state.ip_configuration.private_ip_allocation_method == 'Static'
|
||||
|
||||
- name: Should change virtual network and subnet
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
private_ip_allocation_method: Dynamic
|
||||
virtual_network_name: vnet002
|
||||
subnet: subnet002
|
||||
security_group_name: secgroup002
|
||||
public_ip_address_name: publicip002
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- "'10.20' in output.state.ip_configuration.private_ip_address"
|
||||
- output.state.ip_configuration.private_ip_allocation_method == 'Dynamic'
|
||||
- output.state.ip_configuration.subnet.name == 'subnet002'
|
||||
- output.state.ip_configuration.public_ip_address.name == 'publicip002'
|
||||
|
||||
- name: Add tags
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
tags:
|
||||
testing: testing
|
||||
foo: bar
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 2
|
||||
- output.state.tags.testing == 'testing'
|
||||
|
||||
- name: Gather facts for tags
|
||||
azure_rm_networkinterface_facts:
|
||||
tags: testing
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_networkinterfaces | length >= 1
|
||||
|
||||
- name: Gather facts for resource group and tags
|
||||
azure_rm_networkinterface_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
tags: testing
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_networkinterfaces| length == 1
|
||||
|
||||
- name: Gather facts for name and tags
|
||||
azure_rm_networkinterface_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: nic003
|
||||
tags: testing
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_networkinterfaces | length == 1
|
||||
|
||||
- name: Purge one tag
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
tags:
|
||||
testing: testing
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.tags | length == 1
|
||||
|
||||
- name: Purge all tags
|
||||
azure_rm_networkinterface:
|
||||
name: nic003
|
||||
resource_group: "{{ resource_group }}"
|
||||
tags: {}
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.tags | length == 0
|
||||
|
||||
- name: Remove network interface, if it exists
|
||||
azure_rm_networkinterface:
|
||||
name: "{{ item }}"
|
||||
resource_group: "{{ resource_group }}"
|
||||
state: absent
|
||||
register: output
|
||||
with_items:
|
||||
- nic004
|
||||
- nic005
|
||||
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Remove publicip, if it exists
|
||||
azure_rm_publicipaddress:
|
||||
name: "{{ item }}"
|
||||
resource_group: "{{ resource_group }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- nic00401
|
||||
- nic00501
|
||||
|
||||
- name: Remove security group, if it exists
|
||||
azure_rm_securitygroup:
|
||||
name: "{{ item }}"
|
||||
resource_group: "{{ resource_group }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- nic00401
|
||||
- nic00501
|
||||
|
||||
- name: Should create default security group and default public ip for linux host
|
||||
azure_rm_networkinterface:
|
||||
name: nic004
|
||||
resource_group: "{{ resource_group }}"
|
||||
virtual_network_name: vnet001
|
||||
subnet: subnet001
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.ip_configuration.public_ip_address.name == 'nic00401'
|
||||
- output.state.network_security_group.name == 'nic00401'
|
||||
|
||||
- name: Gather facts for security group nic00401
|
||||
azure_rm_securitygroup_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: nic00401
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_securitygroups[0].properties.securityRules[0].properties.destinationPortRange == '22'
|
||||
|
||||
- name: Should create default security group and default public ip for windows host
|
||||
azure_rm_networkinterface:
|
||||
name: nic005
|
||||
resource_group: "{{ resource_group }}"
|
||||
virtual_network_name: vnet001
|
||||
subnet: subnet001
|
||||
os_type: Windows
|
||||
open_ports:
|
||||
- 9000
|
||||
- '9005-9010'
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.ip_configuration.public_ip_address.name == 'nic00501'
|
||||
- output.state.network_security_group.name == 'nic00501'
|
||||
|
||||
- name: Gather facts for security group nic00501
|
||||
azure_rm_securitygroup_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: nic00501
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Security group should allow RDP access on custom port
|
||||
assert:
|
||||
that:
|
||||
- azure_securitygroups[0].properties.securityRules[0].properties.destinationPortRange == '9000'
|
||||
- azure_securitygroups[0].properties.securityRules[1].properties.destinationPortRange == '9005-9010'
|
||||
|
||||
- name: Gather facts for one nic
|
||||
azure_rm_networkinterface_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: nic003
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_networkinterfaces | length == 1
|
||||
|
||||
- name: Gather facts for all nics in resource groups
|
||||
azure_rm_networkinterface_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_networkinterfaces | length >= 3
|
||||
|
||||
- name: Gather facts for all nics
|
||||
azure_rm_networkinterface_facts:
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_networkinterfaces | length >= 3
|
||||
|
||||
- name: Delete nic
|
||||
azure_rm_networkinterface:
|
||||
name: "{{ item }}"
|
||||
resource_group: "{{ resource_group }}"
|
||||
state: absent
|
||||
register: output
|
||||
with_items:
|
||||
- nic003
|
||||
- nic004
|
||||
- nic005
|
139
test/integration/roles/azure_rm_publicipaddress/tasks/main.yml
Normal file
139
test/integration/roles/azure_rm_publicipaddress/tasks/main.yml
Normal file
|
@ -0,0 +1,139 @@
|
|||
- name: Create resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
location: "{{ location }}"
|
||||
|
||||
- name: Remove public ip
|
||||
azure_rm_publicipaddress:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testing01
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create public ip
|
||||
azure_rm_publicipaddress:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testing01
|
||||
allocation_method: Static
|
||||
domain_name: autotest01
|
||||
tags:
|
||||
testing: testing
|
||||
delete: on-exit
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.public_ip_allocation_method == 'Static'
|
||||
- output.state.dns_settings.domain_name_label == 'autotest01'
|
||||
- output.state.tags | length == 2
|
||||
- output.state.tags.testing == 'testing'
|
||||
|
||||
- name: Should be idempotent
|
||||
azure_rm_publicipaddress:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testing01
|
||||
allocation_method: Static
|
||||
domain_name: autotest01
|
||||
tags:
|
||||
testing: testing
|
||||
delete: on-exit
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: not output.changed
|
||||
|
||||
- name: Update tags
|
||||
azure_rm_publicipaddress:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testing01
|
||||
tags:
|
||||
testing: testing
|
||||
delete: never
|
||||
foo: bar
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 3
|
||||
- output.state.tags.delete == 'never'
|
||||
|
||||
- name: Gather facts, filtering by tag
|
||||
azure_rm_publicipaddress_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
tags:
|
||||
- testing
|
||||
- foo:bar
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_publicipaddresses | length == 1
|
||||
|
||||
- name: Purge all tags
|
||||
azure_rm_publicipaddress:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testing01
|
||||
tags: {}
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 0
|
||||
|
||||
- name: Gather facts for a public ip
|
||||
azure_rm_publicipaddress_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testing01
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_publicipaddresses | length == 1
|
||||
|
||||
- name: Gather facts for all public ips
|
||||
azure_rm_publicipaddress_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_publicipaddresses | length > 0
|
||||
|
||||
- name: Remove all public ips
|
||||
azure_rm_publicipaddress:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ item.name }}"
|
||||
state: absent
|
||||
with_items: "{{ azure_publicipaddresses }}"
|
||||
|
||||
- name: Gather facts for all public ips
|
||||
azure_rm_publicipaddress_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_publicipaddresses | length == 0
|
171
test/integration/roles/azure_rm_resourcegroup/tasks/main.yml
Normal file
171
test/integration/roles/azure_rm_resourcegroup/tasks/main.yml
Normal file
|
@ -0,0 +1,171 @@
|
|||
- name: Create resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
location: "{{ location }}"
|
||||
tags:
|
||||
testing: testing
|
||||
delete: never
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags.testing == 'testing'
|
||||
- output.state.tags.delete == 'never'
|
||||
- output.state.location == '{{ location }}'
|
||||
|
||||
- name: Should be idempotent
|
||||
azure_rm_resourcegroup:
|
||||
name: Testing
|
||||
location: "{{ location }}"
|
||||
tags:
|
||||
testing: testing
|
||||
delete: never
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: not output.changed
|
||||
|
||||
- name: Change resource group tags
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
tags:
|
||||
testing: 'no'
|
||||
delete: 'on-exit'
|
||||
foo: 'bar'
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 3
|
||||
- output.state.tags.testing == 'no'
|
||||
- output.state.tags.delete == 'on-exit'
|
||||
- output.state.tags.foo == 'bar'
|
||||
|
||||
- name: Gather facts by tags
|
||||
azure_rm_resourcegroup_facts:
|
||||
tags:
|
||||
- testing
|
||||
- foo:bar
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_resourcegroups | length == 1
|
||||
|
||||
- name: Purge one tag
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
tags:
|
||||
testing: 'no'
|
||||
delete: 'on-exit'
|
||||
debug: yes
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 2
|
||||
- output.state.tags.testing == 'no'
|
||||
- output.state.tags.delete == 'on-exit'
|
||||
|
||||
- name: Purge no tags
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 2
|
||||
|
||||
- name: Purge all tags
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
tags: {}
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 0
|
||||
|
||||
- name: Add a resource
|
||||
azure_rm_virtualnetwork:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "virtualnet01"
|
||||
address_prefixes_cidr: '10.1.0.0/16'
|
||||
register: output
|
||||
|
||||
- name: Remove resource group should fail
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
state: absent
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.failed
|
||||
- "'Resources exist' in output.msg"
|
||||
|
||||
- name: Create a second resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: Testing2
|
||||
location: "{{ location }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Gather facts for a resource group
|
||||
azure_rm_resourcegroup_facts:
|
||||
name: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_resourcegroups | length == 1
|
||||
|
||||
- name: Gather facts for all resource groups
|
||||
azure_rm_resourcegroup_facts:
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_resourcegroups | length > 1
|
||||
|
||||
- name: Force remove resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
state: absent
|
||||
force: yes
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Remove second resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: Testing2
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
172
test/integration/roles/azure_rm_securitygroup/tasks/main.yml
Normal file
172
test/integration/roles/azure_rm_securitygroup/tasks/main.yml
Normal file
|
@ -0,0 +1,172 @@
|
|||
- name: Create resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
location: "{{ location }}"
|
||||
|
||||
- name: Create security group
|
||||
azure_rm_securitygroup:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: mysecgroup
|
||||
tags:
|
||||
testing: testing
|
||||
delete: on-exit
|
||||
foo: bar
|
||||
purge_rules: yes
|
||||
rules:
|
||||
- name: DenySSH
|
||||
protocol: Tcp
|
||||
destination_port_range: 22
|
||||
access: Deny
|
||||
priority: 100
|
||||
direction: Inbound
|
||||
- name: 'AllowSSH'
|
||||
protocol: Tcp
|
||||
source_address_prefix: '174.109.158.0/24'
|
||||
destination_port_range: 22
|
||||
access: Allow
|
||||
priority: 101
|
||||
direction: Inbound
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert: { that: "{{ output.state.rules | length }} == 2" }
|
||||
|
||||
- name: Gather facts by tags
|
||||
azure_rm_securitygroup_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
tags:
|
||||
- testing
|
||||
- foo:bar
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_securitygroups | length == 1
|
||||
|
||||
- name: Add/Update rules on existing security group
|
||||
azure_rm_securitygroup:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: mysecgroup
|
||||
rules:
|
||||
- name: DenySSH
|
||||
protocol: Tcp
|
||||
destination_port_range: 22-23
|
||||
access: Deny
|
||||
priority: 100
|
||||
- name: AllowSSHFromHome
|
||||
protocol: Tcp
|
||||
source_address_prefix: '174.109.158.0/24'
|
||||
destination_port_range: 22-23
|
||||
priority: 102
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert: { that: "{{ output.state.rules | length }} == 3" }
|
||||
|
||||
- name: Test idempotence
|
||||
azure_rm_securitygroup:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: mysecgroup
|
||||
rules:
|
||||
- name: DenySSH
|
||||
protocol: Tcp
|
||||
destination_port_range: 22-23
|
||||
access: Deny
|
||||
priority: 100
|
||||
- name: AllowSSHFromHome
|
||||
protocol: Tcp
|
||||
source_address_prefix: '174.109.158.0/24'
|
||||
destination_port_range: 22-23
|
||||
priority: 102
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: not output.changed
|
||||
|
||||
- name: Update tags
|
||||
azure_rm_securitygroup:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: mysecgroup
|
||||
tags:
|
||||
testing: testing
|
||||
delete: never
|
||||
baz: bar
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 3
|
||||
- output.state.tags.delete == 'never'
|
||||
|
||||
- name: Purge tags
|
||||
azure_rm_securitygroup:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: mysecgroup
|
||||
tags:
|
||||
testing: testing
|
||||
delete: on-exit
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 2
|
||||
- output.state.tags.delete == 'on-exit'
|
||||
|
||||
- name: Gather facts for one accounts
|
||||
azure_rm_securitygroup_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: mysecgroup
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_securitygroups | length == 1
|
||||
|
||||
- name: Gather facts for all accounts
|
||||
azure_rm_securitygroup_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_securitygroups | length > 0
|
||||
|
||||
- name: Delete all security groups
|
||||
azure_rm_securitygroup:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ item.name }}"
|
||||
state: absent
|
||||
with_items: "{{ azure_securitygroups }}"
|
||||
|
||||
- name: Should have no security groups remaining
|
||||
azure_rm_securitygroup_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- azure_securitygroups | length == 0
|
159
test/integration/roles/azure_rm_storageaccount/tasks/main.yml
Normal file
159
test/integration/roles/azure_rm_storageaccount/tasks/main.yml
Normal file
|
@ -0,0 +1,159 @@
|
|||
- name: Create resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
location: "{{ location }}"
|
||||
|
||||
- name: Test invalid account name
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "invalid_char$"
|
||||
state: present
|
||||
register: invalid_name
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Assert task failed
|
||||
assert: { that: "invalid_name['failed'] == True" }
|
||||
|
||||
- name: Delete storage account
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: teststorageacct002
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create new storage account
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: teststorageacct002
|
||||
account_type: Standard_LRS
|
||||
tags:
|
||||
test: test
|
||||
galaxy: galaxy
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Assert status succeeded and results include an Id value
|
||||
assert:
|
||||
that:
|
||||
- output.changed
|
||||
- output.state.id is defined
|
||||
|
||||
- name: Gather facts by tags
|
||||
azure_rm_storageaccount_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
tags:
|
||||
- test
|
||||
- galaxy
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_storageaccounts | length >= 1
|
||||
|
||||
- name: Change account type
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: teststorageacct002
|
||||
account_type: Premium_LRS
|
||||
register: change_account
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: var=change_account
|
||||
when: playbook_debug
|
||||
|
||||
- name: Assert account type change failed
|
||||
assert: { that: "change_account['failed'] == True" }
|
||||
|
||||
- name: Change account type and add custom domain
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: teststorageacct002
|
||||
account_type: Standard_GRS
|
||||
custom_domain: { name: ansible.com, use_sub_domain: no }
|
||||
register: change_account
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Debug
|
||||
debug: var=change_account
|
||||
when: playbook_debug
|
||||
|
||||
- name: Assert CNAME failure
|
||||
assert: { that: "'custom domain name could not be verified' in change_account['msg']" }
|
||||
|
||||
- name: Update account tags
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: teststorageacct002
|
||||
tags:
|
||||
testing: testing
|
||||
delete: never
|
||||
galaxy: 'no'
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "output.state.tags | length == 3"
|
||||
- "output.state.tags.galaxy == 'no'"
|
||||
|
||||
- name: Update account tags
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: teststorageacct002
|
||||
tags:
|
||||
testing: testing
|
||||
delete: never
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "output.state.tags | length == 2"
|
||||
- "output.state.tags.testing == 'testing'"
|
||||
- "output.state.tags.delete == 'never'"
|
||||
|
||||
- name: Gather facts
|
||||
azure_rm_storageaccount_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: teststorageacct002
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "azure_storageaccounts| length == 1"
|
||||
|
||||
- name: Gather facts
|
||||
azure_rm_storageaccount_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "azure_storageaccounts | length > 0"
|
||||
|
||||
- name: Delete acccount
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: teststorageacct002
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
BIN
test/integration/roles/azure_rm_storageblob/files/Ratings.png
Normal file
BIN
test/integration/roles/azure_rm_storageblob/files/Ratings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
145
test/integration/roles/azure_rm_storageblob/tasks/main.yml
Normal file
145
test/integration/roles/azure_rm_storageblob/tasks/main.yml
Normal file
|
@ -0,0 +1,145 @@
|
|||
- name: Create resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
location: "{{ location }}"
|
||||
|
||||
- name: Create storage account
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testgroup03blobs
|
||||
account_type: Standard_LRS
|
||||
state: present
|
||||
|
||||
- name: Create container
|
||||
azure_rm_storageblob:
|
||||
resource_group: "{{ resource_group }}"
|
||||
account_name: testgroup03blobs
|
||||
container_name: my-blobs
|
||||
register: create_facts
|
||||
|
||||
- debug: var=create_facts
|
||||
when: playbook_debug
|
||||
|
||||
- name: Force upload blob
|
||||
azure_rm_storageblob:
|
||||
resource_group: "{{ resource_group }}"
|
||||
account_name: testgroup03blobs
|
||||
container_name: my-blobs
|
||||
blob: 'Ratings.png'
|
||||
src: './roles/azure_rm_storageblob/files/Ratings.png'
|
||||
content_type: image/png
|
||||
tags:
|
||||
val1: foo
|
||||
val2: bar
|
||||
force: yes
|
||||
register: upload_facts
|
||||
|
||||
- debug: var=upload_facts
|
||||
when: playbook_debug
|
||||
|
||||
- name: Upload blob idempotence
|
||||
azure_rm_storageblob:
|
||||
resource_group: "{{ resource_group }}"
|
||||
account_name: testgroup03blobs
|
||||
container_name: my-blobs
|
||||
blob: 'Ratings.png'
|
||||
src: './roles/azure_rm_storageblob/files/Ratings.png'
|
||||
content_type: image/png
|
||||
tags:
|
||||
val1: foo
|
||||
val2: bar
|
||||
register: upload_facts
|
||||
|
||||
- debug: var=upload_facts
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: "not upload_facts.changed"
|
||||
|
||||
- name: Download file idempotence
|
||||
azure_rm_storageblob:
|
||||
resource_group: "{{ resource_group }}"
|
||||
account_name: testgroup03blobs
|
||||
container_name: my-blobs
|
||||
blob: 'Ratings.png'
|
||||
dest: './roles/azure_rm_storageblob/files/Ratings.png'
|
||||
register: download_results
|
||||
|
||||
- debug: var=download_results
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: not download_results.changed
|
||||
|
||||
- file: path="/tmp/Ratings.png" state=absent
|
||||
|
||||
- name: Download file
|
||||
azure_rm_storageblob:
|
||||
resource_group: "{{ resource_group }}"
|
||||
account_name: testgroup03blobs
|
||||
container_name: my-blobs
|
||||
blob: 'Ratings.png'
|
||||
dest: '/tmp/Ratings.png'
|
||||
register: download_results
|
||||
|
||||
- assert:
|
||||
that: "download_results.changed"
|
||||
|
||||
- find: paths='/tmp' patterns="Ratings.png"
|
||||
register: find_results
|
||||
|
||||
- assert: { that: "find_results['matched'] == 1" }
|
||||
|
||||
- name: Do not delete container that has blobs
|
||||
azure_rm_storageblob:
|
||||
resource_group: "{{ resource_group }}"
|
||||
account_name: testgroup03blobs
|
||||
container_name: my-blobs
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: "not output.changed"
|
||||
|
||||
- name: Delete blob object
|
||||
azure_rm_storageblob:
|
||||
resource_group: "{{ resource_group }}"
|
||||
account_name: testgroup03blobs
|
||||
container_name: my-blobs
|
||||
blob: "Ratings.png"
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: "output.changed"
|
||||
|
||||
- name: Delete container
|
||||
azure_rm_storageblob:
|
||||
resource_group: "{{ resource_group }}"
|
||||
account_name: testgroup03blobs
|
||||
container_name: my-blobs
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: "output.changed"
|
||||
|
||||
- name: Delete storage account
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
location: "{{ location }}"
|
||||
name: testgroup03blobs
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
134
test/integration/roles/azure_rm_subnet/tasks/main.yml
Normal file
134
test/integration/roles/azure_rm_subnet/tasks/main.yml
Normal file
|
@ -0,0 +1,134 @@
|
|||
- name: Create resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
location: "{{ location }}"
|
||||
tags:
|
||||
testing: 'subnet'
|
||||
delete: 'on-exit'
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create virtual network
|
||||
azure_rm_virtualnetwork:
|
||||
name: My_Virtual_Network
|
||||
address_prefixes_cidr:
|
||||
- 10.1.0.0/16
|
||||
- 172.100.0.0/16
|
||||
dns_servers:
|
||||
- 127.0.0.1
|
||||
- 127.0.0.3
|
||||
tags:
|
||||
testing: testing
|
||||
delete: on-exit
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Remove subnet
|
||||
azure_rm_subnet:
|
||||
state: absent
|
||||
name: foobar
|
||||
virtual_network_name: My_Virtual_Network
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Catch invalid cidr
|
||||
azure_rm_subnet:
|
||||
name: foobar
|
||||
virtual_network_name: My_Virtual_Network
|
||||
resource_group: "{{ resource_group }}"
|
||||
address_prefix_cidr: "10.1.0/24"
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: output.failed
|
||||
|
||||
- name: Add the subnet back
|
||||
azure_rm_subnet:
|
||||
name: foobar
|
||||
virtual_network_name: My_Virtual_Network
|
||||
resource_group: "{{ resource_group }}"
|
||||
address_prefix_cidr: "10.1.0.0/24"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: output.changed
|
||||
|
||||
- name: Create network security group
|
||||
azure_rm_securitygroup:
|
||||
name: secgroupfoo
|
||||
resource_group: "{{ resource_group }}"
|
||||
tags:
|
||||
testing: testing
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Update the subnet
|
||||
azure_rm_subnet:
|
||||
name: foobar
|
||||
virtual_network_name: My_Virtual_Network
|
||||
resource_group: "{{ resource_group }}"
|
||||
address_prefix_cidr: "10.1.0.0/16"
|
||||
security_group: secgroupfoo
|
||||
tags:
|
||||
testing: testing
|
||||
delete: on-fini
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Should be idempotent
|
||||
azure_rm_subnet:
|
||||
name: foobar
|
||||
virtual_network_name: My_Virtual_Network
|
||||
resource_group: "{{ resource_group }}"
|
||||
address_prefix_cidr: "10.1.0.0/16"
|
||||
security_group: secgroupfoo
|
||||
tags:
|
||||
testing: testing
|
||||
delete: on-fini
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: not output.changed
|
||||
|
||||
- name: Remove subnet
|
||||
azure_rm_subnet:
|
||||
state: absent
|
||||
name: foobar
|
||||
virtual_network_name: My_Virtual_Network
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- name: Remove security group
|
||||
azure_rm_securitygroup:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: secgroupfoo
|
||||
state: absent
|
||||
|
||||
- name: Remove virtual network
|
||||
azure_rm_virtualnetwork:
|
||||
name: My_Virtual_Network
|
||||
resource_group: "{{ resource_group }}"
|
||||
state: absent
|
||||
register: output
|
|
@ -0,0 +1,8 @@
|
|||
ssh_keys:
|
||||
- path: '/home/chouseknecht/.ssh/authorized_keys'
|
||||
key_data: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC1igsIlcmTa/yfsJnTtnrEX7PP/a01gwbXcig6JOKyrUmJB8E6c/wtZwP115VSyDRTO6TEL/sBFUpkSw01zM8ydNATErh8meBlAlbnDq5NLhDXnMizgG0VNn0iLc/WplFTqkefsHXa8NtIxAtyEVIj/fKbK3XfBOdEpE3+MJYNtGlWyaod28W+5qmQPZDQys+YnE4OjSwN7D3g85/7dtLFvDH+lEC4ooJOaxVFr9VSMXUIkaRF6oI+R1Zu803LFSCTb4BfFOYOHPuQ/rEMP0KuUzggvP+TEBY14PEA2FoHOn+oRsT0ZR2+loGRaxSVqCQKaEHbNbkm+6Rllx2NQRO0BJxCSKRU1iifInLPxmSc4gvsHCKMAWy/tGkmKHPWIfN8hvwyDMK5MNBp/SJ1pVx4xuFDQjVWNbll0yk2+72uJgtFHHwEPK9QsOz45gX85vS3yhYCKrscS/W9h2l36SWwQXuGy4fXotE7esPsvNGAzBndHX1O8RMPg47qJXz059RyoGforoa9TnzIs3hIv+ts7ESx3OEq3HNk0FJ+wDka7IM7WQpGrVToJ0vfDy9Q46nw54vv5Zc/u4OZF3F5twHmyf3rLYKXRDuCvZQKT2iWQKVX6j63bq6orA5hwl22zndxWZNtOwtq8Sd0Ns0K/Fo/ggYDDGBtr68DwhA+MrxrHw== chouseknecht@ansible.com"
|
||||
image:
|
||||
offer: CentOS
|
||||
publisher: OpenLogic
|
||||
sku: '7.1'
|
||||
version: latest
|
|
@ -0,0 +1,2 @@
|
|||
# - include: virtualmachine.yml
|
||||
- include: virtualmachine_with_defaults.yml
|
|
@ -0,0 +1,170 @@
|
|||
- 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
|
|
@ -0,0 +1,120 @@
|
|||
- name: Create resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
location: "{{ location }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Remove VM
|
||||
azure_rm_virtualmachine:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testvm10
|
||||
state: absent
|
||||
register: output
|
||||
when: remove_vm
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Remove VM
|
||||
azure_rm_virtualmachine:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testvm20
|
||||
state: absent
|
||||
register: output
|
||||
when: remove_vm
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create VM with defaults
|
||||
azure_rm_virtualmachine:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testvm10
|
||||
vm_size: Standard_D1
|
||||
admin_username: chouseknecht
|
||||
admin_password: Password123
|
||||
short_hostname: test10
|
||||
os_type: Linux
|
||||
open_ports:
|
||||
- "22-23"
|
||||
image: "{{ image }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Add host
|
||||
add_host:
|
||||
groups: just_created
|
||||
hostname: testvm10
|
||||
ansible_host: "{{ azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties.publicIPAddress.properties.ipAddress }}"
|
||||
ansible_user: chouseknecht
|
||||
ansible_ssh_pass: Password123
|
||||
|
||||
- name: Create VM accessible via ssh keys only
|
||||
azure_rm_virtualmachine:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testvm20
|
||||
short_hostname: testvm20
|
||||
ssh_password_enabled: false
|
||||
ssh_public_keys: "{{ ssh_keys }}"
|
||||
vm_size: Standard_D1
|
||||
admin_username: chouseknecht
|
||||
image: "{{ image }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Should be idempotent
|
||||
azure_rm_virtualmachine:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testvm20
|
||||
short_hostname: testvm20
|
||||
ssh_password_enabled: false
|
||||
ssh_public_keys: "{{ ssh_keys }}"
|
||||
vm_size: Standard_D1
|
||||
admin_username: chouseknecht
|
||||
image: "{{ image }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: not output.changed
|
||||
|
||||
- name: Add host
|
||||
add_host:
|
||||
groups: just_created
|
||||
hostname: testvm20
|
||||
ansible_ssh_host: "{{ azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties.publicIPAddress.properties.ipAddress }}"
|
||||
ansible_ssh_user: chouseknecht
|
||||
|
||||
- name: Power Off
|
||||
azure_rm_virtualmachine:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testvm10
|
||||
started: no
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: "azure_vm.powerstate not in ['starting', 'running']"
|
||||
|
||||
- name: Power On
|
||||
azure_rm_virtualmachine:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: testvm10
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: "azure_vm.powerstate in ['starting', 'running']"
|
|
@ -0,0 +1,52 @@
|
|||
- name: Get facts for a specific image
|
||||
azure_rm_virtualmachineimage_facts:
|
||||
location: "{{ location }}"
|
||||
publisher: OpenLogic
|
||||
offer: CentOS
|
||||
sku: '7.1'
|
||||
version: '7.1.20150731'
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_vmimages | length == 1
|
||||
|
||||
- name: List available versions
|
||||
azure_rm_virtualmachineimage_facts:
|
||||
location: "{{ location }}"
|
||||
publisher: OpenLogic
|
||||
offer: CentOS
|
||||
sku: '7.1'
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_vmimages | length > 0
|
||||
|
||||
- name: List available offers
|
||||
azure_rm_virtualmachineimage_facts:
|
||||
location: "{{ location }}"
|
||||
publisher: OpenLogic
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_vmimages | length > 0
|
||||
|
||||
|
||||
- name: List available publishers
|
||||
azure_rm_virtualmachineimage_facts:
|
||||
location: "{{ location }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: azure_vmimages | length > 0
|
196
test/integration/roles/azure_rm_virtualnetwork/tasks/main.yml
Normal file
196
test/integration/roles/azure_rm_virtualnetwork/tasks/main.yml
Normal file
|
@ -0,0 +1,196 @@
|
|||
- name: Create resource group
|
||||
azure_rm_resourcegroup:
|
||||
name: "{{ resource_group }}"
|
||||
location: westus
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Delete virtual network, if it exists
|
||||
azure_rm_virtualnetwork:
|
||||
name: my_test_network
|
||||
resource_group: "{{ resource_group }}"
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- name: Create virtual network
|
||||
azure_rm_virtualnetwork:
|
||||
name: my_test_network
|
||||
address_prefixes_cidr:
|
||||
- 10.1.0.0/16
|
||||
- 172.100.0.0/16
|
||||
dns_servers:
|
||||
- 127.0.0.1
|
||||
- 127.0.0.3
|
||||
tags:
|
||||
testing: testing
|
||||
delete: on-exit
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "output.state.address_prefixes | length == 2"
|
||||
- "output.state.dns_servers | length == 2"
|
||||
- "output.state.tags.delete == 'on-exit'"
|
||||
- "output.state.tags | length == 2"
|
||||
|
||||
- name: Gather facts by name, tags
|
||||
azure_rm_virtualnetwork_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: my_test_network
|
||||
tags:
|
||||
- testing
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: "azure_virtualnetworks | length == 1"
|
||||
|
||||
- name: Gather facts by resource group, tags
|
||||
azure_rm_virtualnetwork_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
tags:
|
||||
- testing
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: "azure_virtualnetworks | length == 1"
|
||||
|
||||
- name: Gather facts by tags
|
||||
azure_rm_virtualnetwork_facts:
|
||||
tags:
|
||||
- testing
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: "azure_virtualnetworks | length >= 1"
|
||||
|
||||
- name: Should be idempotent
|
||||
azure_rm_virtualnetwork:
|
||||
name: my_test_network
|
||||
address_prefixes_cidr:
|
||||
- 10.1.0.0/16
|
||||
- 172.100.0.0/16
|
||||
dns_servers:
|
||||
- 127.0.0.1
|
||||
- 127.0.0.3
|
||||
tags:
|
||||
testing: testing
|
||||
delete: on-exit
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: not output.changed
|
||||
|
||||
- name: Update tags
|
||||
azure_rm_virtualnetwork:
|
||||
name: my_test_network
|
||||
tags:
|
||||
testing: 'no'
|
||||
delete: never
|
||||
foo: bar
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: output.state.tags | length == 3
|
||||
|
||||
- name: Purge tags
|
||||
azure_rm_virtualnetwork:
|
||||
name: my_test_network
|
||||
tags:
|
||||
testing: 'always'
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.tags | length == 1
|
||||
- output.state.tags.testing == 'always'
|
||||
|
||||
- name: Should require address_prefixes_cidr when purge_address_prefixes
|
||||
azure_rm_virtualnetwork:
|
||||
name: my_test_network
|
||||
purge_address_prefixes: true
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: output.failed
|
||||
|
||||
- name: Purge address prefixes
|
||||
azure_rm_virtualnetwork:
|
||||
name: my_test_network
|
||||
address_prefixes_cidr: 10.1.0.0/16
|
||||
purge_address_prefixes: true
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- output.state.address_prefixes | length == 1
|
||||
- output.state.address_prefixes[0] == '10.1.0.0/16'
|
||||
- output.state.dns_servers | length == 2
|
||||
- output.state.dns_servers[0] == '127.0.0.1'
|
||||
|
||||
- name: Purge DNS servers
|
||||
azure_rm_virtualnetwork:
|
||||
name: my_test_network
|
||||
purge_dns_servers: true
|
||||
resource_group: "{{ resource_group }}"
|
||||
register: output
|
||||
|
||||
- debug: var=output
|
||||
when: playbook_debug
|
||||
|
||||
- assert:
|
||||
that: output.state['dns_servers'] is undefined
|
||||
|
||||
- name: Gather facts
|
||||
azure_rm_virtualnetwork_facts:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: my_test_network
|
||||
register: output
|
||||
|
||||
- assert:
|
||||
that: "azure_virtualnetworks | length == 1"
|
||||
|
||||
- name: Delete virtual network
|
||||
azure_rm_virtualnetwork:
|
||||
name: my_test_network
|
||||
resource_group: "{{ resource_group }}"
|
||||
state: absent
|
||||
register: output
|
Loading…
Reference in a new issue