ansibleguy76 / ansibleforms

A webapplication to create pretty advanced forms to run ansible playbooks or awx templates.
https://ansibleforms.com/
GNU General Public License v3.0
66 stars 10 forks source link

Multistep form always succeeds #173

Closed mdaugs closed 3 months ago

mdaugs commented 3 months ago

Describe the bug A multistep form is always reported as success and all steps are executed even if one step fails.

To Reproduce

  1. Create the following multistep form:
    - name: Demo Form
    type: multistep
    description: Demo Form
    roles:
    - admin
    icon: bullseye
    steps:
    - name: wait for approval
      type: ansible
      playbook: await_approval.yml
      approval:
        title: Please approve demo
        message: |
          You need to approve the demo run.
          Double check please.
        roles:
          - public
      ifExtraVar: var_approval_required
    - name: wait for scheduled start
      type: ansible
      playbook: wait_scheduled_start.yml
      ifExtraVar: var_schedule_job
    - name: Load current Inventory
      type: ansible
      playbook: load_inventory.yml
    - name: Run dummy
      type: ansible
      inventory: /tmp/inventory.yml
      playbook: dummy.yml
    fields:
    - name: var_inventory_url
      type: text
    - name: var_approval_required
      type: checkbox
      label: Request Approval
      group: Preconditions
    - name: var_schedule_job
      type: checkbox
      label: Schedule Job
      width: is-2
      group: Preconditions
      line: schedule_line
    - name: var_scheduled_datetime
      type: datetime
      dateType: datetime
      label: Scheduled Start (Date and Time)
      width: is-3
      dependencies:
        - name: var_schedule_job
          values:
            - true
      group: Preconditions
      line: schedule_line

    The playbooks are defined as:

    # await_approval.yml
    - name: Checking Approval status
    hosts: localhost
    tasks:
    - name: print approval message
      debug:
        msg: "The play has been approved"
    
    # wait_scheduled_start.yml
    - name: Waiting for the scheduled start
    hosts: localhost
    vars:
    var_current_datetime: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}"
    tasks:
    - name: "Calculate the seconds to pause the play."
      set_fact:
        var_wait_seconds: "{{ ((var_scheduled_datetime | to_datetime) - (var_current_datetime | to_datetime)).total_seconds() }}"
    - name: "Show the datetimes and seconds to play the pause."
      debug:
        msg: "{{ var_scheduled_datetime }} :: {{ var_current_datetime }} :: {{ var_wait_seconds }}"
    - name: Wait for starting time
      wait_for:
        timeout: "{{ var_wait_seconds | int }}"
      when: var_wait_seconds | int  > 0
```yaml
# load_inventory.yml
- name: Load Inventory
  hosts: localhost
  tasks:
    - name: Get inventory from URL
      ansible.builtin.get_url:
        dest: /tmp/inventory.yml
        url: "{{ var_inventory_url }}"
# dummy.yaml
- name: Dummy playbook for Demo
  hosts: demo-host # -- Any Host in inventory
  tasks:
    - name: Test connection
      ansible.builtin.ping:
  1. Open the Form
  2. Provide a valid URL to download an inventory
  3. Click 'Schedule Job' but don't provide a date
  4. Run the Form

Expected behavior

  1. The multiform job starts.
  2. The step 'wait for scheduled start' fails
  3. The execution stops and the multiform is reported as failed.

Screenshots image

Version ansibleforms v5.0.1

Deployment Deployed ansibleforms with :

ansibleguy76 commented 3 months ago

That's indeed a new bug. I will need to check when it got introduced and what I changed.

ansibleguy76 commented 3 months ago

Bug is found and fixed. Will push new beta in the next hour.