Issue 1:
ISSUE TYPE

Feature Idea

COMPONENT NAME

Module: ansible/lib/ansible/modules/packaging/language/pip.py

ANSIBLE VERSION

$ ansible --version
ansible 2.2.0.0
config file =
configured module search path = Default w/o overrides

CONFIGURATION

No base config

OS / ENVIRONMENT

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 14.04.4 LTS
Release:	14.04
Codename:	trusty

SUMMARY

The pip module verifies that python libraries with a particular version are installed on the target host. However, it does not support range versions.

STEPS TO REPRODUCE

With support for a range version, the module could be used in a task as follows-

- name: Verify dependencies
pip:
name: docker-py
version: > 1.7.0

Issue 2:
ISSUE TYPE

Feature Idea

COMPONENT NAME

module/cloud/azure/azure_rm_virtualmachine

ANSIBLE VERSION

ansible 2.4.2.0
config file = None
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

CONFIGURATION

OS / ENVIRONMENT

Docker library/centos

SUMMARY

Creating virtual machines on Azure Stack fails because managed disks is not supported.

After spending a lot of time working with the Azure python SDK teams to work around issues with authentication and API versions most objects work correctly however virtual machine creation fails.

STEPS TO REPRODUCE

The steps to reproduce are complicated as changes have to be made to the fix auth, API and model versions for the azure python client to support Azure Stack and a fix to resolve the endpoints provided by Azure Stack via the metadata endpoint.

Obviously an Azure Stack is required to test and for anyone helping with development we have a lab are happy to get people access to.

To make the process easier the following docker container can be used, which implements these fixes.

docker pull charliejllewellyn/azure-tooling:v0.2

The code to build the container is:

FROM library/centos

RUN yum install -y unzip epel-release gcc python-dev openssl git python2-devel ca-certificates vim && yum clean all
RUN yum install -y python-pip && yum clean all
RUN pip install --upgrade pip
RUN pip install ansible[azure]
RUN pip install azure-cli
RUN update-ca-trust force-enable
# Fix for broken authentication
# - https://github.com/Azure/azure-sdk-for-python/issues/1669
RUN sed -i 's/self.cloud_environment.endpoints.management/self.cloud_environment.endpoints.active_directory_resource_id/g' /usr/lib/python2.7/site-packages/msrestazure/azure_active_directory.py
# Fix for hardcoded API's
# - https://github.com/ansible/ansible/issues/26195
# - https://github.com/Azure/azure-sdk-for-python/issues/1696
RUN sed -i '716s/2017-06-01/2016-01-01/g' /usr/lib/python2.7/site-packages/ansible/module_utils/azure_rm_common.py
RUN sed -i 's/2017_06_01/2016_01_01/g' /usr/lib/python2.7/site-packages/azure/mgmt/storage/models.py
RUN sed -i '743s/2017-03-30/2016-03-30/g' /usr/lib/python2.7/site-packages/ansible/module_utils/azure_rm_common.py
RUN sed -i 's/See link below for details./See link below for details.\nfrom .v2016_03_30.models import */g' /usr/lib/python2.7/site-packages/azure/mgmt/compute/models.py
RUN sed -i '725s/2017-06-01/2015-06-15/g' /usr/lib/python2.7/site-packages/ansible/module_utils/azure_rm_common.py
# Fix for lack of storage API with Azure Stack
# - https://github.com/Azure/msrestazure-for-python/issues/64
RUN sed -i "s/requested_vhd_uri \= 'https:\/\/{0}.blob.{1}\/{2}\/{3}'.format(self.storage_account_name,/requested_vhd_uri \= '{0}{1}\/{2}'.format(properties.primary_endpoints.blob,/g" /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
RUN sed -i '/self._cloud_environment.suffixes.storage_endpoint,/d' /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
RUN sed -i 's/self.get_storage_account(self.storage_account_name)/properties = self.get_storage_account(self.storage_account_name)/g' /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py

FYI...I am not proud of this ;)

You then have to save the Azure Stack self signed root cert to /etc/pki/ca-trust/source/anchors/azurestack-physical.cer and import it to the trusted ca store.

update-ca-trust force-enable
update-ca-trust extract
export REQUESTS_CA_BUNDLE=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
cat /root/.azure/azurestack-physical.cer >> /usr/lib/python2.7/site-packages/certifi/cacert.pem

Create a file /root/.azure/credentials with the following content:

[default]
ad_user=username@azurestack-domain
password=xxxxxxxxxxx
subscription_id=<subscription id>
cloud_environment=https://management.local.azurestack.external

Once in place the playbook defined can be run with:

ansible-playbook -i localhost /root/.azure/test.yaml -vvv

---
- hosts: localhost
tasks:
- name: Create a resource group
azure_rm_resourcegroup:
name: Testing
location: local
- name: Create storage account
azure_rm_storageaccount:
resource_group: Testing
name: testaccount001
account_type: Standard_LRS
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: Testing
name: testvn001
address_prefixes: "10.10.0.0/16"
- name: Add subnet
azure_rm_subnet:
resource_group: Testing
name: subnet001
address_prefix: "10.10.0.0/24"
virtual_network: testvn001
- name: Create public ip
azure_rm_publicipaddress:
resource_group: Testing
allocation_method: Static
name: publicip001
- name: Create security group that allows SSH
azure_rm_securitygroup:
resource_group: Testing
name: secgroup001
rules:
- name: SSH
source_address_prefix: '*'
protocol: Tcp
destination_port_range: 22
access: Allow
priority: 101
direction: Inbound
- name: Create NIC
azure_rm_networkinterface:
resource_group: Testing
name: testnic001
virtual_network: testvn001
subnet: subnet001
public_ip_name: publicip001
security_group: secgroup001
- name: Create virtual machine
azure_rm_virtualmachine:
resource_group: Testing
name: testvm001
state: absent
- name: Create virtual machine
azure_rm_virtualmachine:
resource_group: Testing
name: testvm001
vm_size: Standard_D1
storage_account: testaccount001
storage_container: testvm001
storage_blob: testvm001.vhd
admin_username: admin
admin_password: Password!
network_interfaces: testnic001
image:
offer: UbuntuServer
publisher: Canonical
sku: '16.04-LTS'
version: latest

EXPECTED RESULTS

I expect a VM to be created.

ACTUAL RESULTS

VM fails to create because managed disks is not supported on Azure Stack. Really this needs to be resolved by supporting API versions properly and this is likely to be resolved here #26195. @lmazuel and @tstringer I am tagging you on this as you guys seem to be working on solving these challenges :)

We can hack a fix in for this by running:

sed -i '1032s/managed_disk_type = data_disk['managedDisk']['storageAccountType']/#managed_disk_type = data_disk['managedDisk']['storageAccountType']/g' /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
sed -i 's/managed_disk=managed_disk,/#managed_disk=managed_disk,/g' /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
sed -i 's/managed_disk=data_disk_managed_disk,/#managed_disk=data_disk_managed_disk,/g' /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
sed -i 's/self.delete_managed_disks(managed_disk_ids)/#self.delete_managed_disks(managed_disk_ids)/g' /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
sed -i -e '1193,1195d' /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
sed -i -e 's/elif(vm.storage_profile.os_disk.vhd):/if(vm.storage_profile.os_disk.vhd):/g' /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py

TASK [Create virtual machine] ***********************************************************************************************************************************************************************************************************************************************
task path: /root/.azure/test.yaml:59
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1513336142.73-200392836720842 `" && echo ansible-tmp-1513336142.73-200392836720842="` echo /root/.ansible/tmp/ansible-tmp-1513336142.73-200392836720842 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpouWOvA TO /root/.ansible/tmp/ansible-tmp-1513336142.73-200392836720842/azure_rm_virtualmachine.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1513336142.73-200392836720842/ /root/.ansible/tmp/ansible-tmp-1513336142.73-200392836720842/azure_rm_virtualmachine.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1513336142.73-200392836720842/azure_rm_virtualmachine.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1513336142.73-200392836720842/" > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_cOJ_1h/ansible_module_azure_rm_virtualmachine.py", line 1551, in <module>
main()
File "/tmp/ansible_cOJ_1h/ansible_module_azure_rm_virtualmachine.py", line 1548, in main
AzureRMVirtualMachine()
File "/tmp/ansible_cOJ_1h/ansible_module_azure_rm_virtualmachine.py", line 651, in __init__
supports_check_mode=True)
File "/tmp/ansible_cOJ_1h/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 285, in __init__
File "/tmp/ansible_cOJ_1h/ansible_module_azure_rm_virtualmachine.py", line 867, in exec_module
caching=self.os_disk_caching,
TypeError: __init__() got an unexpected keyword argument 'managed_disk'

fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_cOJ_1h/ansible_module_azure_rm_virtualmachine.py\", line 1551, in <module>\n main()\n File \"/tmp/ansible_cOJ_1h/ansible_module_azure_rm_virtualmachine.py\", line 1548, in main\n AzureRMVirtualMachine()\n File \"/tmp/ansible_cOJ_1h/ansible_module_azure_rm_virtualmachine.py\", line 651, in __init__\n supports_check_mode=True)\n File \"/tmp/ansible_cOJ_1h/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 285, in __init__\n File \"/tmp/ansible_cOJ_1h/ansible_module_azure_rm_virtualmachine.py\", line 867, in exec_module\n caching=self.os_disk_caching,\nTypeError: __init__() got an unexpected keyword argument 'managed_disk'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}