For use with eg CentOS.
Assumes you have a file /etc/ansible/hosts with groups and members already configured.
It also assumes you have already created a ssh keypair in your root account.
A properly formatted .yml-file can be found at the end of the article.
This playbook has not been tested!
push.ssh.key.yml
---
- hosts: centos-srv
gather_facts: false
vars:
ssh_key: '/root/.ssh/id_rsa.pub'
tasks:
- name: copy ssh key
authorized_key:
key: "{{ lookup('file', ssh_key) }}"
user: root
...
Sources
https://docs.ansible.com/ansible/2.5/modules/authorized_key_module.html
https://opensource.com/article/17/7/automate-sysadmin-ansible