passing command line arguments

---
- hosts: all
  become: yes
  tasks:
    - name: create an empty folders
      import_tasks: /etc/ansible/foldercreation.yml

    - name: Copy rpm file to server
      copy:
         src: "{{ item }}"
         dest: /home/user/ansible/rpmpackages/
      with_fileglob:
        - /home/user/ansible/rpmpackages/*

    - name: copy the dynatrace file from home to root
      shell: sudo mv /home/user/ansible/rpmpackages/dynatrace-agent-6.1.0.7880-unix.jar /compuware/dt/

      shell: sudo chmod -R 755 /compuware/dt/dynatrace-agent-6.1.0.7880-unix.jar

      shell: sudo chown -R user /compuware/dt/dynatrace-agent-6.1.0.7880-unix.jar

You are missing a dash in front of the shell:

    - name: install dynatrace
      expect:
        command: /opt/SecureSpan/JDK/bin/java -jar /compuware/dt/dynatrace-agent-6.1.0.7880-unix.jar -installDir /compuware/dt/
        responses:
           The product will be installed to /compuware/dt/dynatrace-6.1.0.
Do you want to install to this directory? \(Y/N\): 'Y'

for dynatarce installation I am getting below error , what could be the
reason

TASK [install dynatrace]
***********************************************************************************************************************************************
task path: /etc/ansible/installrpm.yml:28
changed: [server] => {"changed": true, "cmd": "/opt/SecureSpan/JDK/bin/java
-jar /compuware/dt/dynatrace-agent-6.1.0.7880-unix.jar -installDir
/compuware/dt/", "delta": "0:00:00.183363", "end": "2018-02-19
13:33:46.355043", "rc": 0, "start": "2018-02-19 13:33:46.171680", "stdout":
"Invalid argument given!\r\n use <installer> -h to list all the available
arguments", "stdout_lines": ["Invalid argument given!", " use <installer>
-h to list all the available arguments"]}
META: ran handlers
META: ran handlers

It says "Invalid argument given! use <installer> -h to list all the available arguments" so you are running the wrong command in the expect command:.