How to execute two tasks under a play ?

My requirement is to run two tasks i.e “Load Deployment1.” & “Load Deployment2.” in my Play 4.

Below is my playbook:

`

  • name: Play 4
    hosts: localhost
    tasks:
  • name: “Load Deployment1.”
    tags: deploy
    include_vars:
    file: “{{ item }}”
    with_fileglob:
  • “vars/App_*.yaml”

tasks:

  • name: “Load Deployment2.”
    local_action: command ls -ltr checkrun.yml

`

Below is the Output :

[WARNING]: While constructing a mapping from /app/axmw/Ansible/playbook/finacle_deployment/checkrun.yml, line 1, column 3, found a duplicate dict key
(tasks). Using last defined value only.

PLAY [Play 4] ***********************************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************
ok: [localhost]
TASK [Load Deployment2.] ************************************************************************************************************************************
changed: [localhost → localhost]
PLAY RECAP **************************************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

As you can see in the output due to duplicate tasks it ignores the first first and only executes the second task.

How can I change my playbook code so that both the tasks can get executed ?

I dont know why is ansible considering the tasks as duplicate when they are different tasks doing different work? Can’t we have multiple tasks under one play ?

I’m confused. Please help.

Thank you.

No. One play can't have 2 "tasks:" directives. Put "hosts:" directive infront
of the "tasks:"

     - name: Play 4
       hosts: localhost
       tasks:
         - name: "Load Deployment1."
           ...

     - name: Play 4 continue
       hosts: localhost
       tasks:
         - name: "Load Deployment2."
           ...

Cheers,

  -vlado

Is there a reason why single play would not work?

     - name: Play 4
       hosts: localhost
       tasks:
        - name: "Load Deployment1."
          tags: deploy
          include_vars:
            file: "{{ item }}"
          with_fileglob:
            - "vars/App_*.yaml"
        - name: "Load Deployment2."
          local_action: command ls -ltr checkrun.yml

Cheers,

  -vlado

Leave the 2nd “tasks” statement away. Easy fix.