Repository: ansible/awx

Issue:
tower_job_template.py
<!-- Issues are for **concrete, actionable bugs and feature requests** only - if you're just asking for debugging help or technical support, please use:

- http://webchat.freenode.net/?channels=ansible-awx
- https://groups.google.com/forum/#!forum/awx-project

We have to limit this because of limited volunteer time to respond to issues! -->

##### ISSUE TYPE
 - Bug Report

##### SUMMARY
Similar to our issue #7766, we found that this module ignores setting any job template Boolean or Integer parameter values, to its default value.  For example the following parameters can no longer be set as Zero or False after it has been modified via GUI or Tower_Module

        timeout: 3600
        allow_simultaneous: true
        ask_limit_on_launch: true

We only tested a handful of parameters but expect that they all behave in the same way.  We request that all parameters for this module be fully tested

##### ENVIRONMENT

- AWX version: 13.0.0
- AWX install method: we developed an Ansible script to install
- Ansible version: 2.9.11
- Operating System: RHEL Linux 7
- Web Browser: Chromium Edge


##### STEPS TO REPRODUCE

Set any parameter value to something other than its default via GUI or tower_job_template module and then try to set the value back to its default value using tower_job_template module.

##### EXPECTED RESULTS

Module should follow the behavior of AWX GUI and allow parameters to be changed back to their default values

##### ACTUAL RESULTS

Parameter value remains as previously set and will not change back to its default value as directed by tower_job_template payload parameters

##### ADDITIONAL INFORMATION

none



Discussion:
What version of the module? Is it from the 13.0 collection?
Yes - We are using Tower Module 13 with AWX 13
BTW - Same behavior on AWX 15and Modules 15- just tested today

Resolving patch:
diff --git a/awx_collection/plugins/modules/tower_job_template.py b/awx_collection/plugins/modules/tower_job_template.py
--- a/awx_collection/plugins/modules/tower_job_template.py
+++ b/awx_collection/plugins/modules/tower_job_template.py
@@ -436,7 +436,7 @@ def main():
         'become_enabled', 'diff_mode', 'allow_simultaneous', 'custom_virtualenv', 'job_slice_count', 'webhook_service',
     ):
         field_val = module.params.get(field_name)
-        if field_val:
+        if field_val is not None:
             new_fields[field_name] = field_val
 
         # Special treatment of extra_vars parameter


Test patch:
diff --git a/awx_collection/test/awx/test_job_template.py b/awx_collection/test/awx/test_job_template.py
--- a/awx_collection/test/awx/test_job_template.py
+++ b/awx_collection/test/awx/test_job_template.py
@@ -35,6 +35,51 @@ def test_create_job_template(run_module, admin_user, project, inventory):
     assert jt.inventory_id == inventory.id
 
 
+@pytest.mark.django_db
+def test_resets_job_template_values(run_module, admin_user, project, inventory):
+
+    module_args = {
+        'name': 'foo', 'playbook': 'helloworld.yml',
+        'project': project.name, 'inventory': inventory.name,
+        'extra_vars': {'foo': 'bar'},
+        'job_type': 'run',
+        'state': 'present',
+        'forks': 20,
+        'timeout': 50,
+        'allow_simultaneous': True,
+        'ask_limit_on_launch': True,
+    }
+
+    result = run_module('tower_job_template', module_args, admin_user)
+
+    jt = JobTemplate.objects.get(name='foo')
+    assert jt.forks == 20
+    assert jt.timeout == 50
+    assert jt.allow_simultaneous
+    assert jt.ask_limit_on_launch
+
+    module_args = {
+        'name': 'foo', 'playbook': 'helloworld.yml',
+        'project': project.name, 'inventory': inventory.name,
+        'extra_vars': {'foo': 'bar'},
+        'job_type': 'run',
+        'state': 'present',
+        'forks': 0,
+        'timeout': 0,
+        'allow_simultaneous': False,
+        'ask_limit_on_launch': False,
+    }
+
+    result = run_module('tower_job_template', module_args, admin_user)
+    assert result['changed']
+
+    jt = JobTemplate.objects.get(name='foo')
+    assert jt.forks == 0
+    assert jt.timeout == 0
+    assert not jt.allow_simultaneous
+    assert not jt.ask_limit_on_launch
+
+
 @pytest.mark.django_db
 def test_job_launch_with_prompting(run_module, admin_user, project, inventory, machine_credential):
     JobTemplate.objects.create(