搭建一个ansible管理一下机器简单方便

系统:ubuntu 18

安装软件

apt install software-properties-common

apt-add-repository --yes --update ppa:ansible/ansible

apt install ansible

查看版本

ansible --version

创建公钥和私钥

ssh-keygen

将私钥重命名一下

mv id_rsa chia.pem

mv chia.pem ~/

将公钥复制到各个客户端文件/root/.ssh/authorized_keys

注:管理的机器用户名和密码是一样的

测试登录至13的主机里

ssh -i ~/chia.pem  root@192.168.195.13

#!/bin/bash
ssh -i chia.pem root@192.168.194.1${1}:

执行脚本goto.sh 参数写入主机/root/.ssh/known_hosts

配置文件不需要修改/etc/ansible/hosts

[store]
192.168.195.11 ansible_ssh_private_key_file=/root/chia.pem
192.168.195.12 ansible_ssh_private_key_file=/root/chia.pem
192.168.195.13 ansible_ssh_private_key_file=/root/chia.pem
192.168.195.14 ansible_ssh_private_key_file=/root/chia.pem

[liz]
192.168.194.151 ansible_ssh_private_key_file=/root/chia.pem
192.168.194.152 ansible_ssh_private_key_file=/root/chia.pem
192.168.194.154 ansible_ssh_private_key_file=/root/chia.pem
192.168.194.160 ansible_ssh_private_key_file=/root/chia.pem
192.168.194.168 ansible_ssh_private_key_file=/root/chia.pem
192.168.194.172 ansible_ssh_private_key_file=/root/chia.pem
192.168.194.173 ansible_ssh_private_key_file=/root/chia.pem
192.168.194.174 ansible_ssh_private_key_file=/root/chia.pem
192.168.194.175 ansible_ssh_private_key_file=/root/chia.pem
192.168.194.182 ansible_ssh_private_key_file=/root/chia.pem

添加host文件

测试一下 

ansible store -m shell -a "hostname"

192.168.195.12 | CHANGED | rc=0 >>
cslj-012
192.168.195.11 | CHANGED | rc=0 >>
cslj-195-11
192.168.195.13 | CHANGED | rc=0 >>
cslj-195-13
192.168.195.14 | CHANGED | rc=0 >>
cslj-195-14

简单方便的管理自己的机器很方便

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值