<p>For use with eg CentOS.</p>
<p style="margin: 0px 0px 9px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">Assumes you have a file&nbsp;<em style="font-style: italic;">/etc/ansible/hosts</em>&nbsp;with groups and members already configured. <br />It also assumes you have already created a ssh keypair in your root account.</p>
<p style="margin: 0px 0px 9px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;">A properly formatted .yml-file can be found at the end of the article.</p>
<p><strong>This playbook has not been tested!</strong></p>
<p>&nbsp;</p>
<p><strong>push.ssh.key.yml</strong></p>
<pre>---<br />- hosts: centos-srv<br /> gather_facts: false<br /> vars:<br /> ssh_key: '/root/.ssh/id_rsa.pub'<br /> tasks:<br /> - name: copy ssh key<br /> authorized_key:<br /> key: "{{ lookup('file', ssh_key) }}"<br /> user: root<br />...</pre>
<p>&nbsp;</p>
<h2>Sources</h2>
<p><a href="https://docs.ansible.com/ansible/2.5/modules/authorized_key_module.html">https://docs.ansible.com/ansible/2.5/modules/authorized_key_module.html</a></p>
<p><a href="https://opensource.com/article/17/7/automate-sysadmin-ansible">https://opensource.com/article/17/7/automate-sysadmin-ansible</a></p>
<p>&nbsp;</p>

Attachments:
Download this file (push.ssh.keys.yml)push.ssh.keys.yml[push.ssh.keys.yml]0.2 kB