系统: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
简单方便的管理自己的机器很方便