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

 

Stop Spam Harvesters, Join Project Honey Pot

 

Get a free SSL certificate!

 

The leading nonprofit defending digital privacy, free speech, and innovation.

 

The Linux Foundation provides a neutral, trusted hub for developers and organizations to code, manage, and scale open technology projects and ecosystems.

 

Kubuntu is an operating system built by a worldwide community of developers, testers, supporters and translators.

 

 43ef5c89 CanonicalUbuntudarktext