生成秘钥:
    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的文件
    内容如下:

    1. - hosts: test
    2. user: root
    3. tasks:
    4. - name: ssh-copy
    5. authorized_key: user=root key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
    6. tags:
    7. - sshkey
    8. ~
    9. ~

    推送命令: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