Ansible免密登录学习例子

Ansible安装

yum install ansible -y

生成秘钥

ssh-keygen -t RSA

推送公钥给node节点 小数量操作例子

ssh-copy-id -i /root/.ssh/id_rsa.pub 172.16.0.72  #操作第一个
ssh-copy-id -i /root/.ssh/id_rsa.pub 172.16.0.73  #操作第二个

批量推送秘钥例子

# 解决提示主机指纹认证问题
-o StrictHostKeyChecking=no
# 解决密码输入问题:执行yum安装sshpass
yum install sshpass -y
sshpass -p 服务器密码

命令脚本

for i in {72,73};
do
    sshpass -p 123456 ssh-copy-id -i /root/.ssh/id_rsa.pub 172.16.0.$i -o StrictKeyChecking=no
done   

常用操作

ansible node1 -m ping #ping使用
ansible node1 --list-host # 查看组中节点

host写法

#写法一
[组名]
172.16.0.72
172.16.0.73
172.16.0.74
172.16.0.75

[组名:vars] #传参数
ansible_ssh_password=1

#写法二 起别名
[组名]
node01 ansible_ssh_host=172.16.0.72 ansible_ssh_user=root ansible_ssh_password=1 #通过什么用户执行操作
node02 ansible_ssh_host=172.16.0.73  ansible_ssh_user=root ansible_ssh_password=1 ansible_ssh_port=8022
node03 ansible_ssh_host=172.16.0.74 ansible_ssh_user=root ansible_ssh_password=1 
node04 ansible_ssh_host=172.16.0.75 ansible_ssh_user=root ansible_ssh_password=1

[组名:children]
组1
组2 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值