yum module already provides a solution for this problem. The path to the local rpm file on the server can be passed to the
From the Ansible yum module documentation:
You can also pass a url or a local path to a rpm file. To operate on several packages this can accept a comma separated list of packages or (as of 2.0) a list of packages.
The proper steps to do this would be something like this:
- name: Copy rpm file to server
- name: Install package.