Senior
Как раскатать SSH-ключи на 130 серверов через Ansible?
sobes.tech AI
Answer from AI
To distribute SSH keys across 130 servers using Ansible, you can use the authorized_key module, which adds a public key to the ~/.ssh/authorized_keys file of the specified user on the remote server.
Example of a simple playbook:
- hosts: all
become: yes
tasks:
- name: Add public SSH key
authorized_key:
user: your_user
state: present
key: "{{ lookup('file', '/path/to/public_key.pub') }}"
Where:
hosts: all— all 130 servers should be in the inventory.your_user— the user for whom the key is being added.- The public key is stored locally and inserted via
lookup('file', ...).
Run:
ansible-playbook -i inventory_file deploy_ssh_key.yml
This approach is secure, scalable, and does not require manual copying of keys to each server.