From your ansible sever run following command to copy the ssh key to template server.
ssh-copy-id username@IP(template-server)
git clone https://github.com/nirravv/ansible.git
cd ubuntu-scripts
chmod u+x ubuntu-cleanup-template.sh
sudo ./ubuntu-cleanup-template.sh
After that please make a template of your ubuntu-server and use playbook to create future VMs out of it.
vi playbooks/deployments/vars/create_ubuntu_vars.yml
ansible-playbook playbooks/ubuntu-server/create-ubuntu.yml