Repository: ansible/ansible

Issue:
openvswitch_db: ovs-vsctl: "True" is not a valid boolean (use "true" or "false") 
##### SUMMARY
`test/integration/targets/openvswitch_db/tests/basic.yaml:68`

```yaml
{
"changed": false, 
"cmd": "/usr/bin/ovs-vsctl -t 5 set Bridge br-test stp_enable=True", 
"msg": "ovs-vsctl: \"True\" is not a valid boolean (use \"true\" or \"false\")", 
"rc": 1, 
"stderr": "ovs-vsctl: \"True\" is not a valid boolean (use \"true\" or \"false\")\n", 
"stderr_lines": [
"ovs-vsctl: \"True\" is not a valid boolean (use \"true\" or \"false\")"
], 
"stdout": "", 
"stdout_lines": []
}
```

Possibly caused by https://github.com/ansible/ansible/pull/42110
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
openvswitch_db

##### ANSIBLE VERSION
```
2.7
```

##### 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.-->

##### 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

```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```

```



Discussion:
Files identified in the description:
* [lib/ansible/modules/network/ovs/openvswitch_db.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/ovs/openvswitch_db.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 @privateip @rcarrillocruz
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Hi @gundalow,

Thank you for the issue, just so you are aware we have a dedicated Working Group for network.
You can find other people interested in this in #ansible-network on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: community_workgroups --->

Resolving patch:
diff --git a/lib/ansible/modules/network/ovs/openvswitch_db.py b/lib/ansible/modules/network/ovs/openvswitch_db.py
--- a/lib/ansible/modules/network/ovs/openvswitch_db.py
+++ b/lib/ansible/modules/network/ovs/openvswitch_db.py
@@ -120,15 +120,14 @@ def map_obj_to_commands(want, have, module):
                                   "%(col)s"
             commands.append(templatized_command % module.params)
     else:
+        if want == have:
+            # Nothing to commit
+            return commands
         if module.params['key'] is None:
             templatized_command = "%(ovs-vsctl)s -t %(timeout)s set %(table)s %(record)s " \
                                   "%(col)s=%(value)s"
             commands.append(templatized_command % module.params)
-        elif 'key' not in have.keys():
-            templatized_command = "%(ovs-vsctl)s -t %(timeout)s add %(table)s %(record)s " \
-                                  "%(col)s %(key)s=%(value)s"
-            commands.append(templatized_command % module.params)
-        elif want['value'] != have['value']:
+        else:
             templatized_command = "%(ovs-vsctl)s -t %(timeout)s set %(table)s %(record)s " \
                                   "%(col)s:%(key)s=%(value)s"
             commands.append(templatized_command % module.params)
@@ -171,7 +170,7 @@ def map_config_to_obj(module):
             obj['key'] = module.params['key']
             obj['value'] = col_value_to_dict[module.params['key']]
     else:
-            obj['value'] = col_value.strip()
+            obj['value'] = str(col_value.strip())
 
     return obj
 
@@ -199,7 +198,7 @@ def main():
         'record': {'required': True},
         'col': {'required': True},
         'key': {'required': False},
-        'value': {'required': True},
+        'value': {'required': True, 'type': 'str'},
         'timeout': {'default': 5, 'type': 'int'},
     }
 


Test patch:
diff --git a/test/integration/targets/openvswitch_db/tests/basic.yaml b/test/integration/targets/openvswitch_db/tests/basic.yaml
--- a/test/integration/targets/openvswitch_db/tests/basic.yaml
+++ b/test/integration/targets/openvswitch_db/tests/basic.yaml
@@ -70,7 +70,8 @@
     table: Bridge
     record: br-test
     col: stp_enable
-    value: true
+    value: 'true'
+  become: yes
   register: result
 
 - assert:
@@ -82,7 +83,8 @@
     table: Bridge
     record: br-test
     col: stp_enable
-    value: true
+    value: 'true'
+  become: yes
   register: result
 
 - assert:
@@ -96,6 +98,7 @@
     record: br-test
     col: other_config
     value: true
+  become: yes
   register: result
 
 - assert:
diff --git a/test/units/modules/network/ovs/test_openvswitch_db.py b/test/units/modules/network/ovs/test_openvswitch_db.py
--- a/test/units/modules/network/ovs/test_openvswitch_db.py
+++ b/test/units/modules/network/ovs/test_openvswitch_db.py
@@ -114,8 +114,8 @@ def test_openvswitch_db_present_adds_key(self):
                              value='True'))
         self.execute_module(
             changed=True,
-            commands=['/usr/bin/ovs-vsctl -t 5 add Bridge test-br other_config'
-                      ' disable-in-band=True'],
+            commands=['/usr/bin/ovs-vsctl -t 5 set Bridge test-br other_config'
+                      ':disable-in-band=True'],
             test_name='test_openvswitch_db_present_adds_key')
 
     def test_openvswitch_db_present_updates_key(self):