侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

ansible批量推送公钥

2023-10-02 星期一 / 0 评论 / 0 点赞 / 55 阅读 / 2468 字

官方文档使用ssh-keygen -t rsa生成密钥对ssh-keygen -t rsa添加ansible hosts$ cat /etc/ansible/hosts[web]192.168.56.

官方文档

使用ssh-keygen -t rsa生成密钥对

ssh-keygen -t rsa

添加ansible hosts

$ cat /etc/ansible/hosts[web]192.168.56.102 ansible_ssh_user=root ansible_ssh_pass=root ansible_ssh_port=22192.168.56.103 ansible_ssh_user=root ansible_ssh_pass=root ansible_ssh_port=22192.168.56.104 ansible_ssh_user=root ansible_ssh_pass=root ansible_ssh_port=22

修改ansible.cfg

host_key_checking=False# 不用检查host key

编写yaml文件

注意文件格式,不要用tab

$ cat push-ssh.yaml- hosts: web  user: root  tasks:    - name: ssh-key-copy      authorized_key: user=root key="{{ lookup('file','/root/.ssh/id_rsa.pub')}}"      tags:        - sshkey

批量推送

$ ansible-playbook push-ssh.yamlPLAY [web] ***************************************************************************************************************************************************TASK [Gathering Facts] ***************************************************************************************************************************************ok: [192.168.56.104]ok: [192.168.56.103]ok: [192.168.56.102]TASK [ssh-key-copy] ******************************************************************************************************************************************changed: [192.168.56.104]changed: [192.168.56.102]changed: [192.168.56.103]PLAY RECAP ***************************************************************************************************************************************************192.168.56.102             : ok=2    changed=1    unreachable=0    failed=0192.168.56.103             : ok=2    changed=1    unreachable=0    failed=0192.168.56.104             : ok=2    changed=1    unreachable=0    failed=0

验证

[root@localhost ~]# ssh [email protected] login: Fri Jul 14 15:56:00 2017 from 192.168.56.101[root@localhost ~]#[root@localhost ~]# exit登出Connection to 192.168.56.102 closed.[root@localhost ~]# ssh [email protected] login: Fri Jul 14 15:56:10 2017 from 192.168.56.101[root@localhost ~]# exit登出Connection to 192.168.56.102 closed.[root@localhost ~]# ssh [email protected] login: Fri Jul 14 15:56:00 2017 from 192.168.56.101[root@localhost ~]# exit登出Connection to 192.168.56.103 closed

广告 广告

评论区