Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set win_rm protocol to the protocol name, not the ProtocolTypes object #37499

Merged
merged 1 commit into from
Mar 21, 2018

Conversation

01100010011001010110010101110000
Copy link
Contributor

SUMMARY

The azure_rm.py inventory script fails to serialize Windows VMs with the win_rm property set, because the protocol key is set to the full ProtocolTypes object, not to the protocol name property, either http or https

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

azure_rm.py

ANSIBLE VERSION
ansible 2.4.3.0
  config file = None
  configured module search path = ['/Users/tgregory/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ansible
  executable location = bin/ansible
  python version = 3.6.4 (default, Dec 23 2017, 20:35:10) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)]
ADDITIONAL INFORMATION

To reproduce: run the azure_rm.py script against any Windows host with a WinRM listener set to reproduce. Some of the below has been redacted to protect the innocent.

Before:
============
Traceback (most recent call last):
  File "./ansible_src_azure_rm.py", line 860, in <module>
    main()
  File "./ansible_src_azure_rm.py", line 856, in main
    AzureInventory()
  File "./ansible_src_azure_rm.py", line 502, in __init__
    print(self._json_format_dict(pretty=self._args.pretty))
  File "./ansible_src_azure_rm.py", line 745, in _json_format_dict
    return json.dumps(self._inventory, sort_keys=True, indent=2)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 251, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 209, in encode
    chunks = list(chunks)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 442, in _iterencode
    o = _default(o)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <ProtocolTypes.http: 'Http'> is not JSON serializable

After:
============
{
  "Build_Date": [
    "azumsapsc003d"
  ] 
  "Creator": [
    "azumsapsc003d"
  ]
  "_meta": {
    "hostvars": {
      "azumsapsc003d": {
        "ansible_connection": "winrm", 
        "ansible_host": null, 
        "computer_name": "azumsapsc003d", 
        "fqdn": null, 
        "id": "",
        "image": {
          "offer": "WindowsServer", 
          "publisher": "MicrosoftWindowsServer", 
          "sku": "2012-R2-Datacenter", 
          "version": "latest"
        }, 
        "location": "northcentralus", 
        "mac_address": "", 
        "name": "azumsapsc003d", 
        "network_interface": "azumsapsc003d_nic0", 
        "network_interface_id": "", 
        "os_disk": {
          "name": "azumsapsc003d_osDisk", 
          "operating_system_type": "Windows"
        }, 
        "plan": null, 
        "powerstate": "running", 
        "private_ip": "", 
        "private_ip_alloc_method": "Dynamic", 
        "provisioning_state": "Succeeded", 
        "public_ip": null, 
        "public_ip_alloc_method": null, 
        "public_ip_id": null, 
        "public_ip_name": null, 
        "resource_group": "", 
        "tags": { }, 
        "type": "Microsoft.Compute/virtualMachines", 
        "virtual_machine_size": "standard_ds11_v2", 
        "windows_auto_updates_enabled": true, 
        "windows_rm": {
          "listeners": [
            {
              "certificate_url": null, 
              "protocol": "http"
            }
          ]
        }, 
        "windows_timezone": null
      }
    }
  }, 
  "azure": [
    "azumsapsc003d"
  ], 
  "northcentralus": [
    "azumsapsc003d"
  ], 
  "rg_scada_pi": [
    "azumsapsc003d"
  ]
}

@ansibot
Copy link
Contributor

ansibot commented Mar 15, 2018

@ansibot ansibot added azure bug This issue/PR relates to a bug. c:inventory/contrib_script cloud inventory Inventory category needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. python3 support:community This issue/PR relates to code supported by the Ansible community. labels Mar 15, 2018
@yuwzho
Copy link
Contributor

yuwzho commented Mar 16, 2018

shipit

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Mar 16, 2018
@yuwzho
Copy link
Contributor

yuwzho commented Mar 16, 2018

link with #18085

Copy link
Contributor

@jborean93 jborean93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that was an effort an a half to create a VM with the WinRM configuration. Looks good to me.

@jborean93 jborean93 merged commit 6dfc82f into ansible:devel Mar 21, 2018
@dagwieers dagwieers added the windows Windows community label Feb 11, 2019
@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
azure bug This issue/PR relates to a bug. c:inventory/contrib_script cloud inventory Inventory category new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. windows Windows community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants