【ansible】使用ansible安装nginx

一、主机准备

ServerIP:10.10.10.102

ClientIP:  10.10.10.103,10.10.10.104

二、安装ansible

yum -y install ansible

三、配置免密登录

1.在Server上制作公钥和私钥

[root@localhost roles]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:fsarmF7FOVq6/s2ka/VjhEIjbnEcPoQvobEqL1dV63g [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|         .       |
|      . o +      |
|       + B o     |
|      o =.X.     |
|     . oSO*o .   |
|  . . ..+*E.o .  |
|   o . .=.+o.o   |
|  . o  + +.*  +  |
|   o .+.++=.o. . |
+----[SHA256]-----+
[root@localhost roles]# 

2.将Server上的公钥复制到Client上

ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 [email protected]
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 [email protected]
#写入成功后会在10.10.10.103目录~/.ssh/下生成authorized_keys

#验证免密登录是否成功,回车后能登录成功,说明设置成功
ssh root@10.10.10.103

四、编写ansible相关配置文件

1.ansible的目录结构如下

 

猜你喜欢

转载自www.cnblogs.com/xialiaoliao0911/p/9275470.html