0
votes

I would like to generate the ssh key of all my ansible nodes and copy between thems, so all nodes can access among them.

Example:

[nodes]
172.16.8.231 node1
172.16.8.232 node2
172.16.8.233 node3
172.16.8.234 node4

I would like to copy node1, node2, node3 and node4 ssh keys to all nodes.

So node1 can access to node2, node3 and node4. And same for the rest of the nodes.

I generate the ssh key using the next module:

- name: Generate ssh key 
  user:
    name: "{{ user }}"
    generate_ssh_key: yes
    ssh_key_bits: 2048
    ssh_key_file: .ssh/id_rsa

I know how to create the ssh key on one node and copy to others, but what I want is to generate ssh key on all nodes and copy to others.

1

1 Answers

0
votes

I know how to create the ssh key on one node and copy to others

No other knowledge is required:

  1. generate all key-pairs on a control machine,
  2. copy the private keys to their relevant nodes (setting appropriate permissions),
  3. add all public keys to authorized_keys on all nodes,
  4. delete the private keys from the control machine.

Unless you consider your control machine compromised, there is no increased security risk. Especially as the end goal decreases security significantly.