Skip to content

Commit

Permalink
Merge branch 'dev' into securitygroup-stringy-ports
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred-sun authored Apr 28, 2021
2 parents 372853c + e5a5734 commit 5073ac9
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 81 deletions.
2 changes: 1 addition & 1 deletion plugins/doc_fragments/azure_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ModuleDocFragment(object):
plugin:
description: marks this as an instance of the 'azure_rm' plugin
required: true
choices: ['azure_rm']
choices: ['azure_rm', 'azure.azcollection.azure_rm']
include_vm_resource_groups:
description: A list of resource group names to search for virtual machines. '\*' will include all resource
groups in the subscription.
Expand Down
65 changes: 43 additions & 22 deletions tests/integration/targets/inventory_azure/playbooks/setup.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
---
- include_vars:
file: vars.yml
- hosts: localhost
connection: local
gather_facts: no

- name: SETUP | Create storage account
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
account_type: Standard_LRS
tasks:
- include_vars: vars.yml
- name: SETUP | Create storage account
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
account_type: Standard_LRS

- name: SETUP | Create availability set
azure_rm_availabilityset:
name: "{{ availability_set }}"
resource_group: "{{ resource_group }}"
- name: SETUP | Create availability set
azure_rm_availabilityset:
name: "{{ availability_set }}"
resource_group: "{{ resource_group }}"

- name: SETUP | Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ network_name }}"
address_prefixes: "{{ network }}"
- name: SETUP | Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ network_name }}"
address_prefixes: "{{ network }}"

- name: SETUP | Create subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: "{{ subnet_name }}"
address_prefix: "{{ subnet }}"
virtual_network: "{{ network_name }}"
- name: SETUP | Create subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: "{{ subnet_name }}"
address_prefix: "{{ subnet }}"
virtual_network: "{{ network_name }}"

- name: Create minimal VM with defaults
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
admin_username: testuser
ssh_password_enabled: false
ssh_public_keys:
- path: /home/testuser/.ssh/authorized_keys
key_data: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfoYlIV4lTPZTv7hXaVwQQuqBgGs4yeNRX0SPo2+HQt9u4X7IGwrtXc0nEUm6LfaCikMH58bOL8f20NTGz285kxdFHZRcBXtqmnMz2rXwhK9gwq5h1khc+GzHtdcJXsGA4y0xuaNcidcg04jxAlN/06fwb/VYwwWTVbypNC0gpGEpWckCNm8vlDlA55sU5et0SZ+J0RKVvEaweUOeNbFZqckGPA384imfeYlADppK/7eAxqfBVadVvZG8IJk4yvATgaIENIFj2cXxqu2mQ/Bp5Wr45uApvJsFXmi+v/nkiOEV1QpLOnEwAZo6EfFS4CCQtsymxJCl1PxdJ5LD4ZOtP xiuxi.sun@qq.com"
vm_size: Standard_B1ms
virtual_network: "{{ network_name }}"
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: vm_output
58 changes: 36 additions & 22 deletions tests/integration/targets/inventory_azure/playbooks/teardown.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
---
- name: Destroy subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
virtual_network: "{{ network_name }}"
name: "{{ subnet_name }}"
state: absent
- hosts: localhost
connection: local
gather_facts: no

- name: Destroy virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ network_name }}"
state: absent
tasks:
- include_vars: vars.yml

- name: Destroy availability set
azure_rm_availabilityset:
resource_group: "{{ resource_group }}"
name: "{{ availability_set }}"
state: absent
- name: Delete VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
remove_on_absent: all_autocreated
state: absent

- name: Destroy storage account
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
force_delete_nonempty: yes
state: absent
- name: Destroy subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
virtual_network: "{{ network_name }}"
name: "{{ subnet_name }}"
state: absent

- name: Destroy virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ network_name }}"
state: absent

- name: Destroy availability set
azure_rm_availabilityset:
resource_group: "{{ resource_group }}"
name: "{{ availability_set }}"
state: absent

- name: Destroy storage account
azure_rm_storageaccount:
resource_group: "{{ resource_group }}"
name: "{{ storage_account }}"
force_delete_nonempty: yes
state: absent
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,11 @@
connection: local
gather_facts: no
tasks:
- name: setup
include_tasks: setup.yml

- name: Create minimal VM with defaults
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
admin_username: testuser
ssh_password_enabled: false
ssh_public_keys:
- path: /home/testuser/.ssh/authorized_keys
key_data: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfoYlIV4lTPZTv7hXaVwQQuqBgGs4yeNRX0SPo2+HQt9u4X7IGwrtXc0nEUm6LfaCikMH58bOL8f20NTGz285kxdFHZRcBXtqmnMz2rXwhK9gwq5h1khc+GzHtdcJXsGA4y0xuaNcidcg04jxAlN/06fwb/VYwwWTVbypNC0gpGEpWckCNm8vlDlA55sU5et0SZ+J0RKVvEaweUOeNbFZqckGPA384imfeYlADppK/7eAxqfBVadVvZG8IJk4yvATgaIENIFj2cXxqu2mQ/Bp5Wr45uApvJsFXmi+v/nkiOEV1QpLOnEwAZo6EfFS4CCQtsymxJCl1PxdJ5LD4ZOtP xiuxi.sun@qq.com"
vm_size: Standard_B1ms
virtual_network: "{{ network_name }}"
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: vm_output
- include_vars: vars.yml

- meta: refresh_inventory

- name: Test Inventory
assert:
that:
- vm_name in hostvars

- name: Delete VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
remove_on_absent: all_autocreated
state: absent

- name: teardown
include_tasks: teardown.yml
19 changes: 13 additions & 6 deletions tests/integration/targets/inventory_azure/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

set -eux

# ensure test config is empty
# make sure inventory is empty at the begining of the tests
ansible-playbook playbooks/empty_inventory_config.yml "$@"

# create vm
ansible-playbook playbooks/setup.yml "$@"

export ANSIBLE_INVENTORY=test.azure_rm.yml

# generate inventory config and test using it
ansible-playbook playbooks/create_inventory_config.yml "$@"
# using fully qualified name
ansible-playbook playbooks/create_inventory_config.yml "$@"
ansible-playbook playbooks/test_inventory.yml "$@"

# using short name
ansible-playbook playbooks/empty_inventory_config.yml "$@"
ansible-playbook playbooks/create_inventory_config.yml "$@" --extra-vars "template=basic2.yml"
ansible-playbook playbooks/test_inventory.yml "$@"

#ansible-inventory -i test.azure_rm.yml --list -vvv --playbook-dir=./

# cleanup inventory config
ansible-playbook playbooks/empty_inventory_config.yml "$@"
# teardown
ansible-playbook playbooks/teardown.yml "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
plugin: azure_rm
plain_host_names: yes

0 comments on commit 5073ac9

Please sign in to comment.