If you need to generate SSH keys for your root user (or any other user) with Ansible, the following does the trick:
- name: Generate SSH keys
shell: ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""
Why /root/ ?
How about using user -module and generate_ssh_key?