生成秘钥:
ssh-keygen
修改hosts文件
[test]
192.168.100.1 ansible_user=root ansible_ssh_pass=”Gyj@8825” 192.168.100.2 ansible_user=root ansible_ssh_pass=”test”
编写ymal文件
新建.ymal的文件
内容如下:
- hosts: test
user: root
tasks:
- name: ssh-copy
authorized_key: user=root key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
tags:
- sshkey
~
~
推送命令:ansible-playbook push.ssh.ymal
报错解决:
Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host’s fingerprint to your known_hosts file to manage this host.
修改host_key_checking(默认是check的):
vi /home/xiangdong/ansible/ansible.cfg# uncomment this to disable SSH key host checkinghost_key_checking = False