0

I am trying to play around with Ansible dynamic inventory to get software installed/perform configuration management.

I have executed instructions as given by Microsoft here: https://learn.microsoft.com/en-us/azure/ansible/ansible-manage-azure-dynamic-inventories

Commands from my VM are here:

az group create --resource-group ansible-inventory-test-rg --location eastus
az vm create --resource-group ansible-inventory-test-rg              --name ansible-inventory-test-vm1              --image UbuntuLTS --generate-ssh-keys
az vm create --resource-group ansible-inventory-test-rg              --name ansible-inventory-test-vm2              --image UbuntuLTS --generate-ssh-keys
az account show
az resource tag --tags nginx --id /subscriptions/<Subscription ID>/resourceGroups/ansible-inventory-test-rg/providers/Microsoft.Compute/virtualMachines/ansible-inventory-test-vm1
wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/azure_rm.py
chmod +x azure_rm.py
ansible -i azure_rm.py ansible-inventory-test-rg -m ping

However it produces error as below:

[WARNING]:  * Failed to parse /media/sf_C_DRIVE/OnlyOnMyPC/ansible.rhel75.master/azure_rm.py with script plugin: Inventory script
(/media/sf_C_DRIVE/OnlyOnMyPC/ansible.rhel75.master/azure_rm.py) had an execution error: /usr/lib/python2.7/site-packages/requests/__init__.py:91:
RequestsDependencyWarning: urllib3 (1.24.1) or chardet (2.2.1) doesn't match a supported version!   RequestsDependencyWarning) 'Cloud' object has no attribute 'find'

 [WARNING]:  * Failed to parse /media/sf_C_DRIVE/OnlyOnMyPC/ansible.rhel75.master/azure_rm.py with ini plugin:
/media/sf_C_DRIVE/OnlyOnMyPC/ansible.rhel75.master/azure_rm.py:22: Error parsing host definition ''''': No closing quotation

 [WARNING]: Unable to parse /media/sf_C_DRIVE/OnlyOnMyPC/ansible.rhel75.master/azure_rm.py as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

 [WARNING]: Could not match supplied host pattern, ignoring: ansible-inventory-test-rg

I am not surprised to see that it is not working as Technically stuff download from internet won't work directly, there has to have some connection.

I am unable to understand what is the missing link here as I have executed as it is document from Microsoft site, am I missing here anything?

Also how that Python script would know which subscription, which resource group and which VM's it has to apply a particular playbook?

learner
  • 2,480
  • 10
  • 50
  • 94
  • looks like you have typos somewhere in the files and\or that file is outdated. share both files? – 4c74356b41 Feb 24 '19 at 06:21
  • I haven't changed anything from the file I downloaded (wget). wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/azure_rm.py – learner Feb 24 '19 at 07:11
  • Documentation says to use it as it is. It does not mention if we have to supply resource group name, subscription, VM names etc – learner Feb 24 '19 at 07:14
  • Is your `media/sf_C_DRIVE/OnlyOnMyPC/ansible.rhel75.master/azure_rm.py` a Windows Drive? Where are you running your python from? Have you installed ansible[azure] with pip? because it seems you are running from a Virtualbox and the instructions clearly point to a Cloud Shell. Also, there are more instructions than that: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/ansible-install-configure – imjoseangel Feb 24 '19 at 07:29
  • well, it could be outdated, if I were you I'd probably went through the script with pdb or something – 4c74356b41 Feb 24 '19 at 07:34
  • /media/sf_C_DRive is mounted from Windows to Virtualbox VM. My VM is CentOS 7.6 The instructions below are to provision VM with Ansible, I have done with this. My aim is now to create a CICD piple for Infrastructure provisioning. https://learn.microsoft.com/en-us/azure/virtual-machines/linux/ansible-install-configure – learner Feb 24 '19 at 07:35
  • @4c74356b41 There is only one Python File. What is pdb? – learner Feb 24 '19 at 07:38
  • python debugger – 4c74356b41 Feb 24 '19 at 08:04
  • It does not work on cloud shell too, except for the fact that, it does not produces any errors unlike on a VM. – learner Feb 24 '19 at 09:03
  • ansible -i azure_rm.py ansible-inventory-test-rg -m ping [WARNING]: Could not match supplied host pattern, ignoring: ansible-inventory-test-rg [WARNING]: No hosts matched, nothing to do – learner Feb 24 '19 at 09:03

1 Answers1

0

Got it working, maybe there is another better answer than mine but this has got it working.

export AZURE_CLIENT_ID="xxxxxxxxxxxxxxxxxxxxx"
export AZURE_SECRET="xxxxxxxxxxxxxxxxxxxxxxxx"
export AZURE_SUBSCRIPTION_ID="xxxxxxxxxxxxxxx"
export AZURE_TENANT="xxxxxxxxxxxxxxxxxxxxxxxx"

That is it.

learner
  • 2,480
  • 10
  • 50
  • 94