# Buggy code
def __init__(self, network_id, cluster_network, *args, **kwargs):
    super(ClusterNetworksModule, self).__init__(*args, **kwargs)
    self._network_id = network_id
    self._cluster_network = cluster_network


# Traceback (_raise_error)
TASK [set up networks] *****************************************************************************************************************************
task path: /home/djasa/$PROJECT_DIR/playbooks/rhv_setup.yml:84
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/ovirt/ovirt_networks.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: djasa
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/djasa/.ansible/tmp/ansible-tmp-1516804483.42-158332527802812 `" &amp;&amp; echo ansible-tmp-1516804483.42-158332527802812="` echo /home/djasa/.ansible/tmp/ansible-tmp-1516804483.42-158332527802812 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /tmp/tmp4CY5hD TO /home/djasa/.ansible/tmp/ansible-tmp-1516804483.42-158332527802812/ovirt_networks.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/djasa/.ansible/tmp/ansible-tmp-1516804483.42-158332527802812/ /home/djasa/.ansible/tmp/ansible-tmp-1516804483.42-158332527802812/ovirt_networks.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /home/djasa/.ansible/tmp/ansible-tmp-1516804483.42-158332527802812/ovirt_networks.py; rm -rf "/home/djasa/.ansible/tmp/ansible-tmp-1516804483.42-158332527802812/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_xNLAwT/ansible_module_ovirt_networks.py", line 254, in main
ret = cluster_networks_module.create()
File "/tmp/ansible_xNLAwT/ansible_modlib.zip/ansible/module_utils/ovirt.py", line 550, in create
**update_params
File "/usr/lib64/python2.7/site-packages/ovirtsdk4/services.py", line 3620, in update
return self._internal_update(network, headers, query, wait)
File "/usr/lib64/python2.7/site-packages/ovirtsdk4/service.py", line 244, in _internal_update
return future.wait() if wait else future
File "/usr/lib64/python2.7/site-packages/ovirtsdk4/service.py", line 53, in wait
return self._code(response)
File "/usr/lib64/python2.7/site-packages/ovirtsdk4/service.py", line 241, in callback
self._check_fault(response)
File "/usr/lib64/python2.7/site-packages/ovirtsdk4/service.py", line 123, in _check_fault
self._raise_error(response, body)
File "/usr/lib64/python2.7/site-packages/ovirtsdk4/service.py", line 109, in _raise_error
raise error
Error: Fault reason is "Operation Failed". Fault detail is "[Cannot edit Network. Unsetting management network property is not allowed. It is done automatically when moving the role to another network.]". HTTP response code is 400.

failed: [localhost] (item={u'clusters': [{u'assigned': True, u'required': True, u'display': True, u'name': u'Default', u'migration': True}], u'data_center': u'Default', u'name': u'ovirtmgmt', u'vm_network': False, u'mtu': 1500}) => {
"changed": false,
"invocation": {
"module_args": {
"clusters": [
{
"assigned": true,
"display": true,
"migration": true,
"name": "Default",
"required": true
}
],
"comment": null,
"data_center": "Default",
"description": null,
"fetch_nested": false,
"mtu": 1500,
"name": "ovirtmgmt",
"nested_attributes": [],
"poll_interval": 3,
"state": "present",
"timeout": 180,
"vlan_tag": null,
"vm_network": false,
"wait": true
}
},
"item": {
"clusters": [
{
"assigned": true,
"display": true,
"migration": true,
"name": "Default",
"required": true
}
],
"data_center": "Default",
"mtu": 1500,
"name": "ovirtmgmt",
"vm_network": false
}
}

MSG:

Fault reason is "Operation Failed". Fault detail is "[Cannot edit Network. Unsetting management network property is not allowed. It is done automatically when moving the role to another network.]". HTTP response code is 400.

# Fixed code
def __init__(self, network_id, cluster_network, *args, **kwargs):
    super(ClusterNetworksModule, self).__init__(*args, **kwargs)
    self._network_id = network_id
    self._cluster_network = cluster_network
    self._old_usages = []
    self._cluster_network_entity = get_entity(self._service.network_service(network_id))
    if self._cluster_network_entity is not None:
        self._old_usages = self._cluster_network_entity.usages