ansible配置内网服务器免密
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible配置内网服务器免密相关的知识,希望对你有一定的参考价值。
一、安装ansible配置公钥检测(确保通外网或者有epel源)
1、yum安装ansible
2、编辑配置文件关闭公钥检测
vim /etc/ansible/ansible.cfg (先要chmod添加编辑权限)
host_key_checking = False //取消掉它的注释
wq保存退出
二、使用ssh-key产生公钥和私钥
ssh-keygen -t rsa -b 2048 -P -f /root/.ssh/id_rsa
三、添加主机信息到hosts文件
vim /etc/ansible/hosts
[mysql]
192.168.0.2 ansible_ssh_user=root ansible_ssh_pass=passwd
192.168.0.14 ansible_ssh_user=root ansible_ssh_pass=passwd
四、编写playbook脚本key.yml
- hosts: all
gather_facts: no
tasks:
- name: install ssh key authorized_key: user=root key=" lookup(file,/root/.ssh/id_rsa.pub)" state=present
五、执行脚本
ansible-playbook -i hosts key.yml
六、验证
root@briage /etc/ansible]# ssh 192.168.0.2 Authorized users only. All activity may be monitored and reported Last login: Wed Mar 1 23:03:48 2023 from 192.168.0.16
| __ )() __ _ / | | ___ _ _ __| |
| _ \\| |/ | | | |/ _ \\| | | |/ _
|
| |) | | (| | || | () | || | (| |
|/||\\__, |\\||\\/ \\,|\\__,|
|___/
| | __ | | ___ _ __ _ __ _ __()__ ___ | | () __ _ ___ __ | | | \\| / _ \\ | _ \\| | / |/ _ \\ | | | | \\| | | \\ \\/ / | || | | | || / | | |_) | | | \\ \\ / | || | | | | || |> < ||| ||\\\\|| | .__/|| ||/\\| |__||| |_|\\,//\\\\ ||
| | _ __ | | | | ___ _ __ | \\ / | / |/ _ \\ | | / _ \\| | | _| | | | | |/ _ \\ | ) || | | | | | | | | () | | | | | || | | __/ | / __/|| | _ | | || | || \\/|| ||\\,||\\|| |_____|||()||\\___/
Welcome to BigCloud Enterprise Linux For Euler 21.10 (GNU/Linux 4.19.90-2107.6.0.0100.oe1.bclinux.x86_64 x86_64)
System information as of Wed Mar 1 23:07:32 CST 2023
- System CPU load: 0.00 0.00 0.00 * System uptime: 23:07:32 up 1 day
- Active sessions: 2 * Memory usage: 15046 / 15896 MB
- Processes count: 161
- Get Support :
101 packages can be updated. 0 updates are security updates. type yum check-update --security to see details.
以上是关于ansible配置内网服务器免密的主要内容,如果未能解决你的问题,请参考以下文章