CentOS7部署ansible

ansible安装

1.yum安装

[root@localhost  ~]# yum -y install epel-release
[root@localhost  ~]# yum -y install ansible

2.编辑/etc/ansible/hosts文件

[root@localhost ~]# vim /etc/ansible/hosts
[websevers]

192.168.0.37
192.168.0.45
192.168.0.46
192.168.0.47

 3.SSH免密认证

yum install -y sshpass
ssh-keygen -f /root/.ssh/id_rsa -P ''
export IP="192.168.1.37 192.168.1.45 192.168.1.46 192.168.1.47"            #如做host解析,直接使用hostname
export SSHPASS=123123
for HOST in $IP;do
     sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $HOST
done

或者生成ip文件推送密钥

for i in {99..128};do echo 172.16.51.$i >> iplist.txt;done

vim sshpush.sh
#!/usr/bin/bash
export SSHPASS="123456"
for i in `cat /root/iplist.txt`
do
sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $i
done

4.举例

[root@k8s-master01 ~]# ansible al1 -m ping
192.168.0.37 | SUCCESS => {
    "ansible facts":
        "discovered_interpreter_python":"/usr/bin/python"
        },
    "changed": false,
    "ping":"pong"
}
192.168.0.45 | SUCCESS => {
    "ansible facts":
        "discovered_interpreter_python":"/usr/bin/python"
        },
    "changed": false,
    "ping":"pong"
}
192.168.0.46 | SUCCESS => {
    "ansible facts":
        "discovered_interpreter_python":"/usr/bin/python"
        },
    "changed": false,
    "ping":"pong"
}
192.168.0.47 | SUCCESS => {
    "ansible facts":
        "discovered_interpreter_python":"/usr/bin/python"
        },
    "changed": false,
    "ping":"pong"
}
root@k8s-master01 ~# ansible all -m shell -a date
192.168.0.46 | CHANGED | rc=0 >>
Mon Oct 31 13:54:45 CST 2022
192.168.0.45 | CHANGED | rc=0 >>
Mon Oct 31 13:54:45 CST 2022
192.168.0.47 | CHANGED | rc=0 >>
Mon Oct 31 13:54:45 CST 2022
192.168.0.37 | CHANGED | rc=0 >>
Mon Oct 31 13:54:45 CST 2022

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值