Bug 1358048

Summary: Wrong JSON string when generating service dialog on Job Templates for Ansible provider
Product: Red Hat CloudForms Management Engine Reporter: Jerome Marc <jmarc>
Component: ProvidersAssignee: Drew Bomhof <dbomhof>
Status: CLOSED ERRATA QA Contact: Pavol Kotvan <pakotvan>
Severity: high Docs Contact:
Priority: medium    
Version: 5.6.0CC: cpelland, dajohnso, dbomhof, jfrey, jhardy, obarenbo, simaishi
Target Milestone: GAKeywords: ZStream
Target Release: 5.7.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: tower:service:dialog
Fixed In Version: 5.7.0.0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1361173 (view as bug list) Environment:
Last Closed: 2017-01-04 12:58:01 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1361173    

Description Jerome Marc 2016-07-19 23:31:42 UTC
Description of problem:
The JSON string created for default value for extra variables defined as dictionary (list of key/value pairs) when generating a service dialog from a Job Template is incorrect. Ansible job template will fail if using the generated default value for extra variable parameters. User need to manually modify the proposed values with the correct JSON string.

For example: 
I have a job template accepting the following extra variables/default values:
postgresql_users:
  - name: test
    password: test
CloudForms creates the following string when a service dialog is generated from the Job Template:
"[{\"name\"=>\"test\", \"password\"=>\"test\"}]"
The correct extra variable sting should be:
"[{\"name\": \"test\",\"password\": \"test\"}]"

User needs to manually change the extra variable values in the dialog for the Job Template to run successfully.


Version-Release number of selected component (if applicable):
5.6.0.13.20160624114606_13a9153 

How reproducible:
Always


Steps to Reproduce:
1. Create a Job Template in Ansible Tower with extra variable defined as dictionary (list of key/value pairs) and set default values
2. Generate a Service Dialog in CloudForms from the Job Template
3. Add a button launching this job template from a VM/instance with generated dialog

Actual results:
The job template will fail to run with an error on the Ansible Tower side when parsing the extra variable values, something similar to:
FAILED! => {"failed": true, "msg": "'dict object' has no attribute 'password'"}

Expected results:
The default value in the dialog should have been set correctly.

Additional info:
For extra variables set as dictionary, the generated string for default values should use ':' character instead of '=>'.

Comment 4 CFME Bot 2016-07-25 14:20:52 UTC
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/4d82363ce12b53d5c0f5c9d5855beee6ddcd523d

commit 4d82363ce12b53d5c0f5c9d5855beee6ddcd523d
Author:     Bill Wei <bilwei>
AuthorDate: Thu Jul 21 14:26:57 2016 -0400
Commit:     Drew Bomhof <dbomhof>
CommitDate: Fri Jul 22 15:21:03 2016 -0400

    Jsonify the default hash value of an extra var
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1358048

 app/services/ansible_tower_job_template_dialog_service.rb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comment 5 CFME Bot 2016-07-25 14:20:57 UTC
New commit detected on ManageIQ/manageiq/master:
https://github.com/ManageIQ/manageiq/commit/63570343fc631950841e7ef9815279895c449cbc

commit 63570343fc631950841e7ef9815279895c449cbc
Author:     Drew Bomhof <dbomhof>
AuthorDate: Fri Jul 22 17:01:23 2016 -0400
Commit:     Drew Bomhof <dbomhof>
CommitDate: Fri Jul 22 17:22:29 2016 -0400

    Check if a ConfigurationScript has variables with instances of a Hash or an Array
    
    When creating a service dialog from configuration scripts we were not
    encoding the contents of a YAML Hash or Array as JSON.
    
    This fix resolves that issue by calling to_json on
    variable values that are instances of a Hash or Array
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1358048

 app/services/ansible_tower_job_template_dialog_service.rb       | 2 +-
 spec/services/ansible_tower_job_template_dialog_service_spec.rb | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

Comment 11 errata-xmlrpc 2017-01-04 12:58:01 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2017-0012.html