Repository: ansible/ansible

Issue:
azure_rm_securitygroup.py has some problem when creating security group in china region
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report
ansible azrure module cannot create security group in china region.
when I use ansible try to create security group in azure of china region. It will report error to me.
Other function in azure module is successfully. Just azure_rm_securitygroup.py this module does not work.



##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
azure/azure_rm_securitygroup.py

The exception seams raise between  line 439 to 454.

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ubuntu@ip-172-16-1-144:~/mk_az_vm$ ansible --version
ansible 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4]

```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->

Ubuntu 14.04.5 LTS 64 bits

##### SUMMARY
<!--- Explain the problem briefly -->
When playbook try  to create a security group, it will raise an exception, like the below:

TASK [Create security group that allows SSH] ******************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: __init__() got multiple values for keyword argument 'id'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 716, in <module>\n    main()\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 712, in main\n    AzureRMSecurityGroup()\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 542, in __init__\n    supports_check_mode=True)\n  File \"/tmp/ansible_SKpO0N/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 256, in __init__\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 666, in exec_module\n    self.results['state'] = self.create_or_update(results)\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 685, in create_or_update\n    parameters.security_rules.append(create_rule_instance(rule))\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 452, in create_rule_instance\n    etag=rule.get('etag', None)\nTypeError: __init__() got multiple values for keyword argument 'id'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```
---
- hosts: localhost
  connection: local
  tasks:
  - name: Create security group that allows SSH
    azure_rm_securitygroup:
      resource_group: Testing
      name: secgroup001
      rules:
        - name: SSH
          protocol: Tcp
          destination_port_range: 22
          access: Allow
          priority: 101
          direction: Inbound

```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
It should be return ok=1 or changed=1

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->


<!--- Paste verbatim command output between quotes below -->
```
TASK [Create security group that allows SSH] ******************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: __init__() got multiple values for keyword argument 'id'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 716, in <module>\n    main()\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 712, in main\n    AzureRMSecurityGroup()\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 542, in __init__\n    supports_check_mode=True)\n  File \"/tmp/ansible_SKpO0N/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 256, in __init__\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 666, in exec_module\n    self.results['state'] = self.create_or_update(results)\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 685, in create_or_update\n    parameters.security_rules.append(create_rule_instance(rule))\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 452, in create_rule_instance\n    etag=rule.get('etag', None)\nTypeError: __init__() got multiple values for keyword argument 'id'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
	to retry, use: --limit @/home/ubuntu/mk_az_vm/csg.retry

PLAY RECAP ****************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1  
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py b/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
--- a/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
@@ -446,11 +446,11 @@ def create_rule_instance(rule):
     :return: SecurityRule
     '''
     return SecurityRule(
-        rule['protocol'],
-        rule['source_address_prefix'],
-        rule['destination_address_prefix'],
-        rule['access'],
-        rule['direction'],
+        protocol=rule['protocol'],
+        source_address_prefix=rule['source_address_prefix'],
+        destination_address_prefix=rule['destination_address_prefix'],
+        access=rule['access'],
+        direction=rule['direction'],
         id=rule.get('id', None),
         description=rule.get('description', None),
         source_port_range=rule.get('source_port_range', None),


Test patch: