Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory Plugin #11

Merged
merged 6 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ For existing Ansible roles, please also reference the full namespace, collection

## Resource Supported

### Modules

- azure_rm_deployment - Create or destroy Azure Resource Manager template deployments
- azure_rm_dnsrecordset - Create, delete and update DNS record sets and records
- azure_rm_dnsrecordset_facts - Get DNS Record Set facts
Expand All @@ -81,6 +83,10 @@ For existing Ansible roles, please also reference the full namespace, collection
- azure_rm_virtualnetwork - Manage Azure virtual networks
- azure_rm_virtualnetwork_facts - Get virtual network facts

### Plugins

- azure_rm - Azure Resource Manager inventory plugin. Documentation [here](https://docs.ansible.com/ansible/latest/plugins/inventory/azure_rm.html)

## Contributing

There are many ways in which you can participate in the project, for example:
Expand Down
645 changes: 645 additions & 0 deletions plugins/inventory/azure_rm.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/integration/targets/inventory_azure/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/azure
shippable/azure/group1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- hosts: localhost
connection: local
gather_facts: no
vars:
template_name: "../templates/{{ template | default('basic.yml') }}"
tasks:
- name: write inventory config file
copy:
dest: ../test.azure_rm.yml
content: "{{ lookup('template', template_name) }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: write inventory config file
copy:
dest: ../test.azure_rm.yml
content: ""
27 changes: 27 additions & 0 deletions tests/integration/targets/inventory_azure/playbooks/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- include_vars:
file: 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 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 }}"
26 changes: 26 additions & 0 deletions tests/integration/targets/inventory_azure/playbooks/teardown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- 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
@@ -0,0 +1,39 @@
---
- hosts: localhost
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"
admin_password: "Pass123$$$abx!"
vm_size: Standard_B1ms
virtual_network: "{{ network_name }}"
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: vm_output

- 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
14 changes: 14 additions & 0 deletions tests/integration/targets/inventory_azure/playbooks/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
uid: "{{ (resource_group ~ inventory_hostname) | hash('md5') | truncate(18, True, '') }}"
uid_short: "{{ (resource_group ~ inventory_hostname) | hash('md5') | truncate(10, True, '') }}"

storage_account: "{{ 'stor' ~ uid }}"
availability_set: "{{ 'avbs' ~ uid_short }}"
vm_name: "{{ 'vm' ~ uid_short }}"
network_name: "{{ 'vnet' ~ uid_short }}"
subnet_name: "{{ 'snet' ~ uid_short }}"
security_group: "{{ 'sg' ~ uid_short }}"
public_ip_name: "{{ 'ip' ~ uid_short }}"
interface_name: "{{ 'int' ~ uid_short }}"
network: 10.42.0.0/24
subnet: 10.42.0.0/28
17 changes: 17 additions & 0 deletions tests/integration/targets/inventory_azure/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -eux

# ensure test config is empty
ansible-playbook playbooks/empty_inventory_config.yml "$@"

export ANSIBLE_INVENTORY=test.azure_rm.yml

# generate inventory config and test using it
ansible-playbook playbooks/create_inventory_config.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 "$@"
3 changes: 3 additions & 0 deletions tests/integration/targets/inventory_azure/templates/basic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
plugin: azure_rm
plain_host_names: yes
Empty file.