Ansible批量发送密钥
批量发送密钥
# 1.安装ansible
[root@localhost ~]# yum install ansible -y
# 2.根据自己实际的定义主机
[root@localhost ~]# cat /etc/ansible/hosts
[demo]
10.0.1.236 ansible_ssh_host=10.0.1.236 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
# 3.生成密钥
[root@localhost ~]# ssh-keygen -t rsa
# 4.分发密钥
[root@localhost ~]# vim /etc/ansible/ansible.cfg
...
#去掉这个配置的#号
host_key_checking = False
#修改命令行警告
command_warnings = False
[root@localhost ~]# sed -i 's#^\#\(host_key_checking =\).*#\1 False#' /etc/ansible/ansible.cfg
[root@localhost ~]# sed -i 's#^\# \(command_warnings =\).*#\1 False#' /etc/ansible/ansible.cfg
[root@localhost ~]# ansible demo -m authorized_key -a "user=root key='{{lookup('file','/root/.ssh/id_rsa.pub')}}'"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
上次更新: 2025/04/25, 03:40:17