测试环境

系统版本:Ubuntu 20.04

测试部署

172.23.18.100 控制端
172.23.18.11 BPnode1
172.23.18.12 BPnode2
172.23.18.13 BPnode3
172.23.18.53 BYnode1
172.23.18.71 RPC

安装控制端

172.23.18.100

sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible -y

账户规划

为每个机器创建单独用于ansible的账户

sudo useradd ansible
sudo groupadd devops

然后将ansible用户添加到devops组:

sudo usermod -aG devops ansible
sudo mkdir /home/ansible/
sudo chown -R ansible:ansible /home/ansible/
sudo chmod -R 755 /home/ansible/

查看新添加用户

cat /etc/group

为用户设置密码:

sudo passwd ansible

赋予ansible用户使用sudo执行特权命令:

sudo vim /etc/sudoers
ansible ALL=(ALL:ALL) NOPASSWD:ALL
%devops ALL=(ALL) NOPASSWD: ALL

测试已安装

ansible --version

类似输出

ansible [core 2.12.6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/op/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/op/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
  jinja version = 2.10.1
  libyaml = True

切换账户

sudo su - ansible

设置 SSH Key Exchange

Ansible 通过 SSH 连接 client,先在 server 节点生产一个公钥 key,然后将它拷贝到 client 节点上

ssh-keygen
ls /home/当前登录账户名/.ssh/
id_rsa  id_rsa.pub

拷贝公钥 key 至 node 节点

ssh-copy-id op@172.23.18.11
ssh-copy-id op@172.23.18.12
ssh-copy-id op@172.23.18.13
ssh-copy-id op@172.23.18.53
ssh-copy-id op@172.23.18.71

未完待续

参考

https://blog.csdn.net/weixin_40805007/article/details/115033172
https://baijiahao.baidu.com/s?id=1650879841344431164&wfr=spider&for=pc