[基础运维]Ansible的部署

  1. 分发SS
  2. 安装Ansible

1.分发SSH

1.安装sshpass
yum install sshpass -y
2.生成秘钥
输入下方命令后一直按回车结束
[root@k8s-master01 ~]# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
SHA256:pEj0APNNb9czHYRvmIzb090PodH480KvJt/XKStrBuE root@k8s-master01
The key's randomart image is:
+---[DSA 1024]----+
|  o.o .      oo  |
|   + = .   ... . |
|    o o + .o+*.  |
|   . . + o. *o=  |
|    . . S .o * o.|
|         E. + * o|
|          .  o =+|
|           +..oo*|
|          o.o==oo|
+----[SHA256]-----+

3.分发秘钥
[root@k8s-master01 ~]# ssh-copy-id  -i /root/.ssh/id_dsa.pub   root@10.0.0.2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_dsa.pub"
The authenticity of host '10.0.0.2 (10.0.0.2)' can't be established.
ECDSA key fingerprint is SHA256:IuIDvqYaTU/dA4wC21iLNMFsr0p1G5S70rnEi5s7xKc.
ECDSA key fingerprint is MD5:6f:54:e7:50:4c:74:39:09:23:24:7a:79:12:fd:be:78.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@10.0.0.2's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@10.0.0.2'"
and check to make sure that only the key(s) you wanted were added.
4.测试
[root@k8s-master01 ~]# ssh 10.0.0.2
Last login: Tue Sep 28 09:04:00 2021 from 10.0.0.200
[root@learn2 ~]# 

2.安装Ansible

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
yum install -y ansible
1.主机清单
[root@k8s-master01 ~]# cat /etc/ansible/hosts 
[test]
10.0.0.2
10.0.0.3
10.0.0.4
2.测试
[root@k8s-master01 ~]# ansible test -m ping
10.0.0.2 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
10.0.0.3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值