如何將SSH公鑰從每個節點複製到安全服務器?Ansible:如何將公鑰從節點複製到本地?
換句話說:make:ssh-copy-id user @ ansible_server?
我想讓它自動使用劇本文件。
我提出了一些解決方案:
- name: ssh-copy-id
hosts: builder
become: true
tasks:
- name: generate ssh keys on node
user:
name: user
generate_ssh_key: yes
ssh_key_bits: 2048
ssh_key_file: .ssh/id_rsa
- name: get content of public key (node)
shell: cat "/home/user/.ssh/id_rsa.pub"
changed_when: false
register: public_key
- name: append public key from node to local authorized_keys
lineinfile:
line: "{{ public_key.stdout }}"
insertafter: EOF
dest: /local
delegate_to: 127.0.0.1
開始[獲取](HTTP:// docs.ansible.com/ansible/fetch_module.html)。但說實話,你的任務有點奇怪。爲什麼你需要遠程節點的公鑰? –
你爲什麼要那樣做? – techraf
從節點使用rsync(複製日誌到服務器) – themis