---
- name: add tower project
  tower_project:
    name: "{{ vars[demo].project.name }}"
    description: "{{ vars[demo].project.description }}"
    organization: "{{ vars[demo].project.organization }}"
    scm_type: "{{ vars[demo].project.scm_type }}"
    scm_url: "{{ vars[demo].project.scm_url }}"
    tower_username: "{{ my_tower_username }}"
    tower_password: "{{ my_tower_password }}"
    tower_host: "{{ my_tower_host }}"
    validate_certs: false

- name: add single job template without survey
  tower_job_template:
    name: "{{ vars[demo].name }}"
    description: "{{ vars[demo].description }}"
    job_type: "{{ vars[demo].job_type }}"
    inventory: "{{ vars[demo].inventory }}"
    project: "{{ vars[demo].project.name }}"
    playbook: "{{ vars[demo].playbook }}"
    fact_caching_enabled: "{{ vars[demo].fact_caching_enabled | default('false') }}"
    credential: "{{ vars[demo].credential }}"
    survey_enabled: "{{ vars[demo].survey_enabled }}"
    tower_username: "{{ my_tower_username }}"
    tower_password: "{{ my_tower_password }}"
    tower_host: "{{ my_tower_host }}"
    validate_certs: false
  when:
    - workshop_type in vars[demo].workshop_type
    - not vars[demo].survey_enabled
  register: add_job_template
  until: add_job_template is not failed
  retries: 5

- name: add single job template with survey
  tower_job_template:
    name: "{{ vars[demo].name }}"
    description: "{{ vars[demo].description }}"
    job_type: "{{ vars[demo].job_type }}"
    inventory: "{{ vars[demo].inventory }}"
    project: "{{ vars[demo].project.name }}"
    playbook: "{{ vars[demo].playbook }}"
    fact_caching_enabled: "{{ vars[demo].fact_caching_enabled | default('false') }}"
    credential: "{{ vars[demo].credential }}"
    survey_enabled: "{{ vars[demo].survey_enabled }}"
    survey_spec: "{{ vars[demo].survey_spec }}"
    tower_username: "{{ my_tower_username }}"
    tower_password: "{{ my_tower_password }}"
    tower_host: "{{ my_tower_host }}"
    validate_certs: false
  when:
    - workshop_type in vars[demo].workshop_type
    - vars[demo].survey_enabled
  register: add_job_template
  until: add_job_template is not failed
  retries: 5
