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

tower_workflow_template module fails in parser for extra vars #6167

Closed
kedark3 opened this issue Mar 4, 2020 · 4 comments
Closed

tower_workflow_template module fails in parser for extra vars #6167

kedark3 opened this issue Mar 4, 2020 · 4 comments
Assignees
Labels
component:awx_collection issues related to the collection for controlling AWX type:bug

Comments

@kedark3
Copy link

kedark3 commented Mar 4, 2020

ISSUE TYPE
  • Bug Report
SUMMARY

While using extra_vars with tower_workflow_template module, it fails to parse the variables.

ENVIRONMENT
  • Tower version: 3.6.2
  • AWX install method: linux using bundle
  • Ansible version: 2.9.1 on Tower, 2.9.2 on my local system from where I run the playbook
  • Operating System: not relevant I believe
  • Web Browser: N/A
STEPS TO REPRODUCE

Use tower_workflow_template ansible module to create workflow and pass it following data:

tower_workflows:
  - name: Test workflow
    description: created by Ansible Playbook
    organization: Default
    survey_enabled: false
    allow_simultaneous: no
    schema:
      - job_template: Demo Job Template
    extra_vars:
      var1: val1
      var2:
        var21: val21
        var22: val22
      var3:
        - var4
        - var5
      var6:
        - var7: val7
        - var8: val8
          var9: val9

Sample Playbook could look like:

- name: Play
  hosts: < IP/Hostname of your Tower>
  tasks:
  - name: Create ansible tower workflows
    tower_workflow_template:
      allow_simultaneous:           "{{ workflow.allow_simultaneous | default('no') }}"
      ask_extra_vars:               "{{ workflow.ask_extra_vars | default('no') }}"
      ask_inventory:                "{{ workflow.ask_inventory | default('no') }}"
      description:                  "{{ workflow.description | default('Created using Ansible Role') }}"
      extra_vars:                   "{{ workflow.extra_vars | default(omit) }}"
      inventory:                    "{{ workflow.inventory | default(omit) }}"
      name:                         "{{ workflow.name }}"
      organization:                 "{{ workflow.organization | default(omit) }}"
      schema:                       "{{ workflow.schema }}"
      state:                        "{{ workflow.state | default('present') }}"
      survey:                       "{{ workflow.survey | default(omit) }}"
      survey_enabled:               "{{ workflow.survey_enabled | default('no') }}"
      tower_host:                   "{{ tower_hostname }}"
      tower_username:               admin
      tower_password:               "{{tower_admin_password}}"
      tower_verify_ssl:             false
    loop: "{{ tower_workflows }}"
    loop_control:
      loop_var: workflow
EXPECTED RESULTS

Workflow should be created with correct extra_vars

ACTUAL RESULTS
The full traceback is:
Traceback (most recent call last):
  File "<stdin>", line 102, in <module>
  File "<stdin>", line 94, in _ansiballz_main
  File "<stdin>", line 40, in invoke_module
  File "/usr/lib64/python2.7/runpy.py", line 176, in run_module
    fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/tmp/ansible_tower_workflow_template_payload_sphiyR/ansible_tower_workflow_template_payload.zip/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_template.py", line 203, in <module>
  File "/tmp/ansible_tower_workflow_template_payload_sphiyR/ansible_tower_workflow_template_payload.zip/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_template.py", line 187, in main
  File "/usr/lib/python2.7/site-packages/tower_cli/models/base.py", line 720, in modify
    return self.write(pk, create_on_missing=create_on_missing, force_on_exists=True, **kwargs)
  File "/usr/lib/python2.7/site-packages/tower_cli/models/base.py", line 1187, in write
    kwargs['extra_vars'] = parser.process_extra_vars(kwargs['extra_vars'])
  File "/usr/lib/python2.7/site-packages/tower_cli/utils/parser.py", line 130, in process_extra_vars
    opt_dict = string_to_dict(extra_vars_opt, allow_kv=True)
  File "/usr/lib/python2.7/site-packages/tower_cli/utils/parser.py", line 105, in string_to_dict
    'variables.\nvariables: \n%s' % var_string
tower_cli.exceptions.TowerCLIError: failed to parse some of the extra variables.
variables: 
{
ADDITIONAL INFORMATION
@kedark3
Copy link
Author

kedark3 commented Mar 4, 2020

A possible fix that I tested and worked well for me was like this: ansible/tower-cli#748

@AlanCoding AlanCoding added component:awx_collection issues related to the collection for controlling AWX state:needs_devel type:bug and removed state:needs_devel labels Mar 4, 2020
@ryanpetrello
Copy link
Contributor

ryanpetrello commented Mar 13, 2020

@AlanCoding is this ready for needs_test or is there more work to do (I see a merged PR linked).

@AlanCoding
Copy link
Member

no, this should be totally wrapped up.

Note for QE:

It was originally feared that this would break old use cases, where someone provides a JSON-formatted string. This is not the case, because Ansible core does generous duck typing, will recognize this case and parse it into a dict. The only case that we lose support for is where someone provides a list of dicts, which only ever worked due to a code error.

@squidboylan
Copy link
Contributor

tested by #6297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:awx_collection issues related to the collection for controlling AWX type:bug
Projects
None yet
Development

No branches or pull requests

6 participants