Repository: ansible/ansible

Issue:
azure_rm_sqldatabase has started failing with deserialization error
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
I am seeing an error while creating Azure SQL databases. I am not sure when this started happening, since we don't run these scripts often. This script was working a few weeks ago.


##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->
azure_rm_sqldatabase

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.3
  config file = None
  configured module search path = ['/home/arc/.ansible/plugins/modules', '/usr/share/ansible/plugin/modules']
  ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, 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, BELOW THIS COMMENT, 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 subsystem in Windows 10


##### 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 -->
```yaml
- name: "Creating a SQL server  {{ sql_srv_name }}"
      azure_rm_sqlserver:
        resource_group: "{{ resource_group }}"
        name: "{{ sql_srv_name }}"
        location: "{{ location }}"
        admin_username: "{{ sql_admin_user }}"
        admin_password: "{{ sql_admin_password }}"

    - name: "Creating a SQL database  {{ sql_db_name }}"
      azure_rm_sqldatabase:
        resource_group: "{{ resource_group }}"
        server_name: "{{ sql_srv_name }}"
        name: "{{ sql_db_name }}"
        location: "{{ location }}"
        edition: "{{ sql_edition }}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Not an error.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
TASK [Creating a SQL database  op18db] **********************************************************************************************************
task path: /mnt/c/source/tmp/scripts/amp:79
Using module file /usr/local/lib/python3.5/dist-packages/ansible/modules/cloud/azure/azure_rm_sqldatabase.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: op
<127.0.0.1> EXEC /bin/sh -c 'echo ~op && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/op/.ansible/tmp/ansible-tmp-1529512576.7917314-267487385500822 `" && echo ansible-tmp-1529512576.7917314-267487385500822="` echo /home/op/.ansible/tmp/ansible-tmp-1529512576.7917314-267487385500822 `" ) && sleep 0'
<127.0.0.1> PUT /home/op/.ansible/tmp/ansible-local-6921efz19cjc/tmpwg4r2sow TO /home/op/.ansible/tmp/ansible-tmp-1529512576.7917314-267487385500822/azure_rm_sqldatabase.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/op/.ansible/tmp/ansible-tmp-1529512576.7917314-267487385500822/ /home/op/.ansible/tmp/ansible-tmp-1529512576.7917314-267487385500822/azure_rm_sqldatabase.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/op/.ansible/tmp/ansible-tmp-1529512576.7917314-267487385500822/azure_rm_sqldatabase.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/op/.ansible/tmp/ansible-tmp-1529512576.7917314-267487385500822/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1167, in deserialize_data
    return self.deserialize_basic(data, data_type)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1278, in deserialize_basic
    raise TypeError("Invalid boolean value: {}".format(attr))
TypeError: Invalid boolean value: Disabled

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 467, in body
    data = deserializer(data_type, data)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1023, in __call__
    value = self.deserialize_data(raw_value, attr_desc['type'])
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1185, in deserialize_data
    raise_with_traceback(DeserializationError, msg, err)
  File "/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py", line 45, in raise_with_traceback
    raise error.with_traceback(exc_traceback)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1167, in deserialize_data
    return self.deserialize_basic(data, data_type)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1278, in deserialize_basic
    raise TypeError("Invalid boolean value: {}".format(attr))
msrest.exceptions.DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py", line 499, in <module>
    main()
  File "/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py", line 496, in main
    AzureRMDatabases()
  File "/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py", line 312, in __init__
    supports_tags=False)
  File "/tmp/ansible_ow89qgmk/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 345, in __init__
  File "/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py", line 395, in exec_module
    response = self.create_update_sqldatabase()
  File "/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py", line 438, in create_update_sqldatabase
    parameters=self.parameters)
  File "/usr/local/lib/python3.5/dist-packages/azure/mgmt/sql/operations/databases_operations.py", line 344, in create_or_update
    **operation_config
  File "/usr/local/lib/python3.5/dist-packages/azure/mgmt/sql/operations/databases_operations.py", line 286, in _create_or_update_initial
    body_content = self._serialize.body(parameters, 'Database')
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 470, in body
    SerializationError, "Unable to build a model: "+str(err), err)
  File "/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py", line 45, in raise_with_traceback
    raise error.with_traceback(exc_traceback)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 467, in body
    data = deserializer(data_type, data)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1023, in __call__
    value = self.deserialize_data(raw_value, attr_desc['type'])
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1185, in deserialize_data
    raise_with_traceback(DeserializationError, msg, err)
  File "/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py", line 45, in raise_with_traceback
    raise error.with_traceback(exc_traceback)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1167, in deserialize_data
    return self.deserialize_basic(data, data_type)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1278, in deserialize_basic
    raise TypeError("Invalid boolean value: {}".format(attr))
msrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled, DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled

fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1167, in deserialize_data\n    return self.deserialize_basic(data, data_type)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1278, in deserialize_basic\n    raise TypeError(\"Invalid boolean value: {}\".format(attr))\nTypeError: Invalid boolean value: Disabled\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 467, in body\n    data = deserializer(data_type, data)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1023, in __call__\n    value = self.deserialize_data(raw_value, attr_desc['type'])\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1185, in deserialize_data\n    raise_with_traceback(DeserializationError, msg, err)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py\", line 45, in raise_with_traceback\n    raise error.with_traceback(exc_traceback)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1167, in deserialize_data\n    return self.deserialize_basic(data, data_type)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1278, in deserialize_basic\n    raise TypeError(\"Invalid boolean value: {}\".format(attr))\nmsrest.exceptions.DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py\", line 499, in <module>\n    main()\n  File \"/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py\", line 496, in main\n    AzureRMDatabases()\n  File \"/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py\", line 312, in __init__\n    supports_tags=False)\n  File \"/tmp/ansible_ow89qgmk/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 345, in __init__\n  File \"/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py\", line 395, in exec_module\n    response = self.create_update_sqldatabase()\n  File \"/tmp/ansible_ow89qgmk/ansible_module_azure_rm_sqldatabase.py\", line 438, in create_update_sqldatabase\n    parameters=self.parameters)\n  File \"/usr/local/lib/python3.5/dist-packages/azure/mgmt/sql/operations/databases_operations.py\", line 344, in create_or_update\n    **operation_config\n  File \"/usr/local/lib/python3.5/dist-packages/azure/mgmt/sql/operations/databases_operations.py\", line 286, in _create_or_update_initial\n    body_content = self._serialize.body(parameters, 'Database')\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 470, in body\n    SerializationError, \"Unable to build a model: \"+str(err), err)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py\", line 45, in raise_with_traceback\n    raise error.with_traceback(exc_traceback)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 467, in body\n    data = deserializer(data_type, data)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1023, in __call__\n    value = self.deserialize_data(raw_value, attr_desc['type'])\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1185, in deserialize_data\n    raise_with_traceback(DeserializationError, msg, err)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py\", line 45, in raise_with_traceback\n    raise error.with_traceback(exc_traceback)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1167, in deserialize_data\n    return self.deserialize_basic(data, data_type)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1278, in deserialize_basic\n    raise TypeError(\"Invalid boolean value: {}\".format(attr))\nmsrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled, DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 1
}
        to retry, use: --limit @/mnt/c/source/tmp/scripts/amp.retry

PLAY RECAP *******************************************************************************************************************************************
localhost                  : ok=12   changed=2    unreachable=0    failed=1
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @zikalino
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Hi @vpopescu , I have try your YML and PASS result, my test environment same with you (ansible 2.5.3), I think your error may cause by some naming not match ansible's conventions, could you can share your all variable and name.
My YML and execute result as below,  Could you can try again. Thanks a lot!
``` e.g.
---
- name: for SQL server test
  hosts: localhost
  vars:
    resource_group: myRG01
    sql_srv_name: fredsql001
    location: westeurope
    sql_admin_user: azureuser
    sql_admin_password: Password@0329
    sql_db_name: freddb001
    sql_edition: standard
  tasks:
    - name: create resource groupo
      azure_rm_resourcegroup:
        name: "{{ resource_group }}"
        location: "{{ location }}"
    - name: "Creating a SQL server  {{ sql_srv_name }}"
      azure_rm_sqlserver:
        resource_group: "{{ resource_group }}"
        name: "{{ sql_srv_name }}"
        location: "{{ location }}"
        admin_username: "{{ sql_admin_user }}"
        admin_password: "{{ sql_admin_password }}"

    - name: "Creating a SQL database  {{ sql_db_name }}"
      azure_rm_sqldatabase:
        resource_group: "{{ resource_group }}"
        server_name: "{{ sql_srv_name }}"
        name: "{{ sql_db_name }}"
        location: "{{ location }}"
        edition: "{{ sql_edition }}"

Result:
fred@fred-Virtual-Machine:~/task/41742$ ansible-playbook 41742.yml 

PLAY [for SQL server test] *****************************************************

TASK [Gathering Facts] *********************************************************
ok: [127.0.0.1]

TASK [create resource groupo] **************************************************
ok: [127.0.0.1]

TASK [Creating a SQL server  fredsql001] ***************************************
 [WARNING]: Azure API profile latest does not define an entry for
SqlManagementClient

ok: [127.0.0.1]

TASK [Creating a SQL database  freddb001] **************************************
changed: [127.0.0.1]

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=4    changed=1    unreachable=0    failed=0   

fred@fred-Virtual-Machine:~/task/41742$ ansible --version
ansible 2.5.3
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/fred/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]


I am experiencing this exact same issue with Ansible 2.5.5 running on RedHat 7.5.
Sorry,  Could you can try my YML and share your YML file let me try , Thanks a lot!
I ran your yml.

PLAY [for SQL server test] ****************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [create resource groupo] *************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Creating a SQL server  WeEu-S03-Dev-Sql-webm-01] ************************************************************************************************************************************************************
 [WARNING]: Azure API profile latest does not define an entry for SqlManagementClient

changed: [localhost]

TASK [Creating a SQL database  freddb001] *************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: msrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled, DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_DORgNG/ansible_module_azure_rm_sqldatabase.py\", line 499, in <module>\n    main()\n  File \"/tmp/ansible_DORgNG/ansible_module_azure_rm_sqldatabase.py\", line 496, in main\n    AzureRMDatabases()\n  File \"/tmp/ansible_DORgNG/ansible_module_azure_rm_sqldatabase.py\", line 312, in __init__\n    supports_tags=False)\n  File \"/tmp/ansible_DORgNG/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 345, in __init__\n  File \"/tmp/ansible_DORgNG/ansible_module_azure_rm_sqldatabase.py\", line 395, in exec_module\n    response = self.create_update_sqldatabase()\n  File \"/tmp/ansible_DORgNG/ansible_module_azure_rm_sqldatabase.py\", line 438, in create_update_sqldatabase\n    parameters=self.parameters)\n  File \"/usr/lib/python2.7/site-packages/azure/mgmt/sql/operations/databases_operations.py\", line 710, in create_or_update\n    body_content = self._serialize.body(parameters, 'Database')\n  File \"/usr/lib/python2.7/site-packages/msrest/serialization.py\", line 470, in body\n    SerializationError, \"Unable to build a model: \"+str(err), err)\n  File \"/usr/lib/python2.7/site-packages/msrest/exceptions.py\", line 48, in raise_with_traceback\n    raise error\nmsrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled, DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}
        to retry, use: --limit @/home/ofmwadmin/test2.retry

PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=1

My yml is the same as vpopescu.
@Fred-sun Your script fails for me as well, the same way. I used your script, and just modified the group name and server name by adding "b" to the name.
Hi @vpopescu , I have tried my script( group name and server name by adding 'b' to the name), But ran successfully. Could your help share your ran script, Another, tell me your test environment and ansible version. Thanks a lot!
``` e.g.
---
- name: for SQL server test
  hosts: localhost
  vars:
    resource_group: myRG01b
    sql_srv_name: fredsql001b
    location: westeurope
    sql_admin_user: azureuser
    sql_admin_password: Password@0329
    sql_db_name: freddb001b
    sql_edition: standard
  tasks:
    - name: create resource groupo
      azure_rm_resourcegroup:
        name: "{{ resource_group }}"
        location: "{{ location }}"
    - name: "Creating a SQL server  {{ sql_srv_name }}"
      azure_rm_sqlserver:
        resource_group: "{{ resource_group }}"
        name: "{{ sql_srv_name }}"
        location: "{{ location }}"
        admin_username: "{{ sql_admin_user }}"
        admin_password: "{{ sql_admin_password }}"
      register: server_dump
    - name: dump create server log
      debug: 
        var: server_dump

    - name: "Creating a SQL database  {{ sql_db_name }}"
      azure_rm_sqldatabase:
        resource_group: "{{ resource_group }}"
        server_name: "{{ sql_srv_name }}"
        name: "{{ sql_db_name }}"
        location: "{{ location }}"
        edition: "{{ sql_edition }}"
      register: db_dump
    - name: dump create db sql log
      debug:
        var: db_dump

Execute Result:
fred@fred-Virtual-Machine:~/task/41742$ ansible-playbook  test01.yml 

PLAY [for SQL server test] *****************************************************

TASK [Gathering Facts] *********************************************************
ok: [127.0.0.1]

TASK [create resource groupo] **************************************************
ok: [127.0.0.1]

TASK [Creating a SQL server  fredsql001b] **************************************
 [WARNING]: Azure API profile latest does not define an entry for
SqlManagementClient

ok: [127.0.0.1]

TASK [dump create server log] **************************************************
ok: [127.0.0.1] => {
    "server_dump": {
        "changed": false, 
        "failed": false, 
        "fully_qualified_domain_name": "fredsql001b.database.windows.net", 
        "id": "/subscriptions/2085065b-00f8-4cba-9675-ba15f4d4ab66/resourceGroups/myRG01b/providers/Microsoft.Sql/servers/fredsql001b", 
        "state": "Ready", 
        "version": "12.0", 
        "warnings": [
            "Azure API profile latest does not define an entry for SqlManagementClient"
        ]
    }
}

TASK [Creating a SQL database  freddb001b] *************************************
ok: [127.0.0.1]

TASK [dump create db sql log] **************************************************
ok: [127.0.0.1] => {
    "db_dump": {
        "changed": false, 
        "database_id": "2dd7a242-1d4e-47b6-944a-d5c4ab8b6c26", 
        "failed": false, 
        "id": "/subscriptions/2085065b-00f8-4cba-9675-ba15f4d4ab66/resourceGroups/myRG01b/providers/Microsoft.Sql/servers/fredsql001b/databases/freddb001b", 
        "status": "Online", 
        "warnings": [
            "Azure API profile latest does not define an entry for SqlManagementClient"
        ]
    }
}

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=6    changed=0    unreachable=0    failed=0 


Hi @jelledebruin66 , Servername  principle : cannot be empty or null, It can only be made up of lowercase letters 'a'-'z', the numbers 0-9 and the hyphen, the hyphen may not lead or tail in the name. Could follow this principle and try again. Thanks a lot!
@Fred-sun My script is your script. I'm running Ansible 2.5.3. My test environment is totally clean (I'm trying it in my azure account linked to my MSDN subscription, and I deleted every single resource group before running this script. Is there a way I can see the HTTP response from the server, so I can post it?


```yaml
- name: for SQL server test
  hosts: localhost
  vars:
    resource_group: myRG01d
    sql_srv_name: fredsql001d
    location: centralus
    sql_admin_user: azureuser
    sql_admin_password: Password@0329
    sql_db_name: freddb001
    sql_edition: standard
  tasks:
    - name: create resource groupo
      azure_rm_resourcegroup:
        name: "{{ resource_group }}"
        location: "{{ location }}"
    - name: "Creating a SQL server  {{ sql_srv_name }}"
      azure_rm_sqlserver:
        resource_group: "{{ resource_group }}"
        name: "{{ sql_srv_name }}"
        location: "{{ location }}"
        admin_username: "{{ sql_admin_user }}"
        admin_password: "{{ sql_admin_password }}"

    - name: "Creating a SQL database  {{ sql_db_name }}"
      azure_rm_sqldatabase:
        resource_group: "{{ resource_group }}"
        server_name: "{{ sql_srv_name }}"
        name: "{{ sql_db_name }}"
        location: "{{ location }}"
        edition: "{{ sql_edition }}"
```

and failure... after this failure, the SQL server is created, but the database is not. I changed the zone to centralus because I'm having timeouts with westeurope today. But the error was the same on westeurope too.




```
$ ansible-playbook -vvvv pb.yaml
ansible-playbook 2.5.3
  config file = None
  configured module search path = ['/home/otp/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
No config file found; using defaults
setting up inventory plugins
 [WARNING]: Unable to parse /etc/ansible/hosts 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'

Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.5/dist-packages/ansible/plugins/callback/default.py

PLAYBOOK: pb.yaml ***********************************************************************************************************************************************************************************************************************************
1 plays in pb.yaml

PLAY [for SQL server test] **************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************************************************************
task path: /mnt/c/tmp/pb.yaml:1
Using module file /usr/local/lib/python3.5/dist-packages/ansible/modules/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: otp
<127.0.0.1> EXEC /bin/sh -c 'echo ~otp && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/otp/.ansible/tmp/ansible-tmp-1529991775.6721125-162141337403776 `" && echo ansible-tmp-1529991775.6721125-162141337403776="` echo /home/otp/.ansible/tmp/ansible-tmp-1529991775.6721125-162141337403776 `" ) && sleep 0'
<127.0.0.1> PUT /home/otp/.ansible/tmp/ansible-local-23202wxzjpcxi/tmp6g0htd54 TO /home/otp/.ansible/tmp/ansible-tmp-1529991775.6721125-162141337403776/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/otp/.ansible/tmp/ansible-tmp-1529991775.6721125-162141337403776/ /home/otp/.ansible/tmp/ansible-tmp-1529991775.6721125-162141337403776/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/otp/.ansible/tmp/ansible-tmp-1529991775.6721125-162141337403776/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/otp/.ansible/tmp/ansible-tmp-1529991775.6721125-162141337403776/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [create resource groupo] ***********************************************************************************************************************************************************************************************************************
task path: /mnt/c/tmp/pb.yaml:12
Using module file /usr/local/lib/python3.5/dist-packages/ansible/modules/cloud/azure/azure_rm_resourcegroup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: otp
<127.0.0.1> EXEC /bin/sh -c 'echo ~otp && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/otp/.ansible/tmp/ansible-tmp-1529991778.8767967-188543706207119 `" && echo ansible-tmp-1529991778.8767967-188543706207119="` echo /home/otp/.ansible/tmp/ansible-tmp-1529991778.8767967-188543706207119 `" ) && sleep 0'
<127.0.0.1> PUT /home/otp/.ansible/tmp/ansible-local-23202wxzjpcxi/tmpmur6hj9a TO /home/otp/.ansible/tmp/ansible-tmp-1529991778.8767967-188543706207119/azure_rm_resourcegroup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/otp/.ansible/tmp/ansible-tmp-1529991778.8767967-188543706207119/ /home/otp/.ansible/tmp/ansible-tmp-1529991778.8767967-188543706207119/azure_rm_resourcegroup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/otp/.ansible/tmp/ansible-tmp-1529991778.8767967-188543706207119/azure_rm_resourcegroup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/otp/.ansible/tmp/ansible-tmp-1529991778.8767967-188543706207119/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {
    "changed": true,
    "contains_resources": false,
    "invocation": {
        "module_args": {
            "ad_user": null,
            "api_profile": "latest",
            "append_tags": true,
            "auth_source": null,
            "cert_validation_mode": null,
            "client_id": null,
            "cloud_environment": null,
            "force": false,
            "location": "centralus",
            "name": "myRG01d",
            "password": null,
            "profile": null,
            "secret": null,
            "state": "present",
            "subscription_id": null,
            "tags": null,
            "tenant": null
        }
    },
    "state": {
        "id": "/subscriptions/0f2f4954-26bf-4aed-bc0c-24ffc80d1c18/resourceGroups/myRG01d",
        "location": "centralus",
        "name": "myRG01d",
        "provisioning_state": "Succeeded",
        "tags": null
    }
}

TASK [Creating a SQL server  fredsql001d] ***********************************************************************************************************************************************************************************************************
task path: /mnt/c/tmp/pb.yaml:16
Using module file /usr/local/lib/python3.5/dist-packages/ansible/modules/cloud/azure/azure_rm_sqlserver.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: otp
<127.0.0.1> EXEC /bin/sh -c 'echo ~otp && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/otp/.ansible/tmp/ansible-tmp-1529991782.254035-24632579629717 `" && echo ansible-tmp-1529991782.254035-24632579629717="` echo /home/otp/.ansible/tmp/ansible-tmp-1529991782.254035-24632579629717 `" ) && sleep 0'
<127.0.0.1> PUT /home/otp/.ansible/tmp/ansible-local-23202wxzjpcxi/tmp_81xcvf8 TO /home/otp/.ansible/tmp/ansible-tmp-1529991782.254035-24632579629717/azure_rm_sqlserver.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/otp/.ansible/tmp/ansible-tmp-1529991782.254035-24632579629717/ /home/otp/.ansible/tmp/ansible-tmp-1529991782.254035-24632579629717/azure_rm_sqlserver.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/otp/.ansible/tmp/ansible-tmp-1529991782.254035-24632579629717/azure_rm_sqlserver.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/otp/.ansible/tmp/ansible-tmp-1529991782.254035-24632579629717/ > /dev/null 2>&1 && sleep 0'
 [WARNING]: Azure API profile latest does not define an entry for SqlManagementClient

changed: [localhost] => {
    "changed": true,
    "fully_qualified_domain_name": "fredsql001d.database.windows.net",
    "id": "/subscriptions/0f2f4954-26bf-4aed-bc0c-24ffc80d1c18/resourceGroups/myRG01d/providers/Microsoft.Sql/servers/fredsql001d",
    "invocation": {
        "module_args": {
            "ad_user": null,
            "admin_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "admin_username": "azureuser",
            "api_profile": "latest",
            "append_tags": true,
            "auth_source": null,
            "cert_validation_mode": null,
            "client_id": null,
            "cloud_environment": null,
            "identity": null,
            "location": "centralus",
            "name": "fredsql001d",
            "password": null,
            "profile": null,
            "resource_group": "myRG01d",
            "secret": null,
            "state": "present",
            "subscription_id": null,
            "tags": null,
            "tenant": null,
            "version": null
        }
    },
    "state": "Ready",
    "version": "12.0"
}

TASK [Creating a SQL database  freddb001] ***********************************************************************************************************************************************************************************************************
task path: /mnt/c/tmp/pb.yaml:24
Using module file /usr/local/lib/python3.5/dist-packages/ansible/modules/cloud/azure/azure_rm_sqldatabase.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: otp
<127.0.0.1> EXEC /bin/sh -c 'echo ~otp && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/otp/.ansible/tmp/ansible-tmp-1529991868.6343338-2098437110477 `" && echo ansible-tmp-1529991868.6343338-2098437110477="` echo /home/otp/.ansible/tmp/ansible-tmp-1529991868.6343338-2098437110477 `" ) && sleep 0'
<127.0.0.1> PUT /home/otp/.ansible/tmp/ansible-local-23202wxzjpcxi/tmpdk_2ezzj TO /home/otp/.ansible/tmp/ansible-tmp-1529991868.6343338-2098437110477/azure_rm_sqldatabase.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/otp/.ansible/tmp/ansible-tmp-1529991868.6343338-2098437110477/ /home/otp/.ansible/tmp/ansible-tmp-1529991868.6343338-2098437110477/azure_rm_sqldatabase.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/otp/.ansible/tmp/ansible-tmp-1529991868.6343338-2098437110477/azure_rm_sqldatabase.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/otp/.ansible/tmp/ansible-tmp-1529991868.6343338-2098437110477/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1167, in deserialize_data
    return self.deserialize_basic(data, data_type)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1278, in deserialize_basic
    raise TypeError("Invalid boolean value: {}".format(attr))
TypeError: Invalid boolean value: Disabled

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 467, in body
    data = deserializer(data_type, data)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1023, in __call__
    value = self.deserialize_data(raw_value, attr_desc['type'])
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1185, in deserialize_data
    raise_with_traceback(DeserializationError, msg, err)
  File "/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py", line 45, in raise_with_traceback
    raise error.with_traceback(exc_traceback)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1167, in deserialize_data
    return self.deserialize_basic(data, data_type)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1278, in deserialize_basic
    raise TypeError("Invalid boolean value: {}".format(attr))
msrest.exceptions.DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py", line 499, in <module>
    main()
  File "/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py", line 496, in main
    AzureRMDatabases()
  File "/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py", line 312, in __init__
    supports_tags=False)
  File "/tmp/ansible_s94hrh_1/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 345, in __init__
  File "/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py", line 395, in exec_module
    response = self.create_update_sqldatabase()
  File "/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py", line 438, in create_update_sqldatabase
    parameters=self.parameters)
  File "/usr/local/lib/python3.5/dist-packages/azure/mgmt/sql/operations/databases_operations.py", line 344, in create_or_update
    **operation_config
  File "/usr/local/lib/python3.5/dist-packages/azure/mgmt/sql/operations/databases_operations.py", line 286, in _create_or_update_initial
    body_content = self._serialize.body(parameters, 'Database')
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 470, in body
    SerializationError, "Unable to build a model: "+str(err), err)
  File "/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py", line 45, in raise_with_traceback
    raise error.with_traceback(exc_traceback)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 467, in body
    data = deserializer(data_type, data)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1023, in __call__
    value = self.deserialize_data(raw_value, attr_desc['type'])
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1185, in deserialize_data
    raise_with_traceback(DeserializationError, msg, err)
  File "/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py", line 45, in raise_with_traceback
    raise error.with_traceback(exc_traceback)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1167, in deserialize_data
    return self.deserialize_basic(data, data_type)
  File "/usr/local/lib/python3.5/dist-packages/msrest/serialization.py", line 1278, in deserialize_basic
    raise TypeError("Invalid boolean value: {}".format(attr))
msrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled, DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled

fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1167, in deserialize_data\n    return self.deserialize_basic(data, data_type)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1278, in deserialize_basic\n    raise TypeError(\"Invalid boolean value: {}\".format(attr))\nTypeError: Invalid boolean value: Disabled\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 467, in body\n    data = deserializer(data_type, data)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1023, in __call__\n    value = self.deserialize_data(raw_value, attr_desc['type'])\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1185, in deserialize_data\n    raise_with_traceback(DeserializationError, msg, err)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py\", line 45, in raise_with_traceback\n    raise error.with_traceback(exc_traceback)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1167, in deserialize_data\n    return self.deserialize_basic(data, data_type)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1278, in deserialize_basic\n    raise TypeError(\"Invalid boolean value: {}\".format(attr))\nmsrest.exceptions.DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py\", line 499, in <module>\n    main()\n  File \"/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py\", line 496, in main\n    AzureRMDatabases()\n  File \"/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py\", line 312, in __init__\n    supports_tags=False)\n  File \"/tmp/ansible_s94hrh_1/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 345, in __init__\n  File \"/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py\", line 395, in exec_module\n    response = self.create_update_sqldatabase()\n  File \"/tmp/ansible_s94hrh_1/ansible_module_azure_rm_sqldatabase.py\", line 438, in create_update_sqldatabase\n    parameters=self.parameters)\n  File \"/usr/local/lib/python3.5/dist-packages/azure/mgmt/sql/operations/databases_operations.py\", line 344, in create_or_update\n    **operation_config\n  File \"/usr/local/lib/python3.5/dist-packages/azure/mgmt/sql/operations/databases_operations.py\", line 286, in _create_or_update_initial\n    body_content = self._serialize.body(parameters, 'Database')\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 470, in body\n    SerializationError, \"Unable to build a model: \"+str(err), err)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py\", line 45, in raise_with_traceback\n    raise error.with_traceback(exc_traceback)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 467, in body\n    data = deserializer(data_type, data)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1023, in __call__\n    value = self.deserialize_data(raw_value, attr_desc['type'])\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1185, in deserialize_data\n    raise_with_traceback(DeserializationError, msg, err)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/exceptions.py\", line 45, in raise_with_traceback\n    raise error.with_traceback(exc_traceback)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1167, in deserialize_data\n    return self.deserialize_basic(data, data_type)\n  File \"/usr/local/lib/python3.5/dist-packages/msrest/serialization.py\", line 1278, in deserialize_basic\n    raise TypeError(\"Invalid boolean value: {}\".format(attr))\nmsrest.exceptions.SerializationError: Unable to build a model: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled, DeserializationError: Unable to deserialize response data. Data: Disabled, bool, TypeError: Invalid boolean value: Disabled\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 1
}
        to retry, use: --limit @/mnt/c/tmp/pb.retry

PLAY RECAP ******************************************************************************************************************************************************************************************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=1
```
@Fred-sun Applied the principle but got the same error.

Resolving patch:
diff --git a/lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py b/lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py
--- a/lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py
@@ -346,7 +346,7 @@ def exec_module(self, **kwargs):
                         ev = 'AdventureWorksLT'
                     self.parameters["sample_name"] = ev
                 elif key == "zone_redundant":
-                    self.parameters["zone_redundant"] = 'Enabled' if kwargs[key] else 'Disabled'
+                    self.parameters["zone_redundant"] = True if kwargs[key] else False
 
         old_response = None
         response = None


Test patch: