Ansible第一章----配置

主机名 ip
master 192.168.88.100
node1 192.168.88.139

1、免秘登录

Ansible 使用普通用户管理被控端

场景说明:ansible使用ansible普通用户统一管理所有被控节点(用户名随意)

①首先控制端,被控制端都需要创建ansible用户

useradd ansible
echo '123456' | passwd --stdin ansible

②受控端产生一对公私钥,并且即将公钥发给受控端

[root@master ~]# su - ansible 

[ansible@master ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ansible/.ssh/id_rsa): 
Created directory '/home/ansible/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ansible/.ssh/id_rsa
Your public key has been saved in /home/ansible/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:TvEUpPRsftPpRz4FTr0BTMDeWjrDMU5ivFsRdQrOym4 ansible@master
The key's randomart image is:
+---[RSA 3072]----+
|        ..+o=+ . |
|       . +o+..+. |
|        + *oo.o..|
|        .X.* * oo|
|        SoO X +.o|
|       o.. X o o.|
|        .Eo o ..o|
|        ..     ..|
|                 |
+----[SHA256]-----+



[root@master ~]# ll /home/ansible/.ssh
total 16
-rw-------. 1 root root 2590 Apr 11 16:17 id_rsa
-rw-r--r--. 1 root root  565 Apr 11 16:17 id_rsa.pub

[root@master ~]# ssh-cpoy-id -i /root/.ssh/id_rsa.pub [email protected]
[email protected]'s password:
id_rsa.pub                                  100%  565   910.1KB/s   00:00                                                             

Ansible第一章----配置_第1张图片  

③所有主机的 ansible 用户都必须添加 sudo 权限

vim /etc/sudoers
ansible ALL=(ALL)       NOPASSWD: ALL

④编辑/etc/hosts文件

192.168.88.139 node1

2、写主机清单文件

mkdir /home/ansible/inventory

vim /home/ansible/inventory

[web]
192.168.88.139
node1

3、写ansible配置文件/etc/ansible/ansible.cfg

[defaults]
inventory=/home/ansible/inventory
host_key_checking=False
remote_user=ansible
ask_pass=False
[privilege_escalation]
become=true
become_method=sudo
become_user=root
become_ask_pass=false   

4、测试(在ansible用户下)

Ansible第一章----配置_第2张图片

 

你可能感兴趣的:(ansible,服务器,linux)