Implementing your own Ansible Azure Collection

Introduction

Updating the Azure Ansible Collection

pip install ansible
git clone https://github.com/ansible-collections/azure.git
pip install -r azure/requirements-azure.txt
cp azure/plugins/modules/azure_rm_resource_info.py azure/plugins/modules/azure_rm_resource_info_rt.py
class AzureRMResourceInfoRT(AzureRMModuleBase)...self.module_arg_spec = dict(
url=dict(type='str'),
provider=dict(type='list'),
...
location=dict(type='str')
)
...
self.location = None...
def exec_module(self, **kwargs):
...
self.mgmt_client = self.get_mgmt_svc_client(GenericRestClient, base_url="https://"+self.location+".management.azure.com/")
#Generate collection tarball (--force to replace if ran previously)
ansible-galaxy collection build --force
#Install the collection tarball (--force to reinstall)
ansible-galaxy collection install azure-azcollection-*.tar.gz --force
- name: AKS Demo Ansible Playbook on Azure Cloud Shell
hosts: localhost
tasks:
- name: List all VMScaleSets in the rsg1 Resource Group
azure.azcollection.azure_rm_resource_info_rt:
resource_group: rsg1
provider: compute
resource_type: virtualmachinescalesets
api_version: "2017-12-01"
location: northeurope
register: vmssresources
until: vmssresources.response[0].name is defined
retries: 20
delay: 60
- debug:
var: vmssresources
ansible-playbook ans.yaml

Conclusion

--

--

Cloud Platform Architect. Opinions and articles on medium are my own.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian Hynes

Cloud Platform Architect. Opinions and articles on medium are my own.