当前位置:网站首页>快速学会ansible的安装
快速学会ansible的安装
2022-08-02 20:50:00 【我是渣渣辉】
1、自定义环境
准备大于等于三台主机
角色 | 主机名 | ip地址 | 组名 |
---|---|---|---|
控制主机 | server.example.com | 192.168.189.129 | server |
受控主机/被管节点 | node1.example.com | 192.168.189.134 | node1 |
受控主机/被管节点 | node2.example.com | 192.168.189.135 | node2 |
(1)配置ip
给三台主机配置静态IP
nmcli c mo ens160 ipv4.addresses 172.25.250.100/24 ipv4.gateway 192.168.189.2 ipv4.dns 8.8.8.8 ipv4.method manual connection.autoconnect yes
nmcli connection up ens160 # 重启连接
(2)多台主机配置主机名并且确保多台主机能够通过主机名互访
hostnamectl set-hostname server.example.com
hostnamectl set-hostname node1.example.com
hostnamectl set-hostname node2.example.com
在每台主机的/etc/hosts中配置
192.168.189.129 server.example.com
192.168.189.134 node1.example.com
192.168.189.135 node2.example.com
(3) 多台主机通过ssh远程连接实现免密登陆
生成秘钥
ssh-keygen -t rsa -P '' -q -f ~/.ssh/id_rsa
将公钥钥拷贝到另外两台主机的用户家目录下的/.ssh/authorized_keys 中(没有的话,创建)
scp /root/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
scp /root/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
(4) 如果是通过普通用户管理受控主机,需要通过sudo提权。
2、在控制主机上安装ansible
(1)配置epel扩展源
release 一般带这个东西指的是软件厂库.repo
yum install -y https://mirrors.tuna.tsinghua.edu.cn/epel/epel-release-latest-8.noarch.rpm
(2)yum install ansible -y
由于Redhat8版本过高,而ansible-code版本过低,会导致安装错误
conflicting requests - nothing provides (ansible-core >= 2.12.2 with ansible-code < 2.12.3)
以下有两种解决办法:
一、直接更改软件yum源,此yum源放入/etc/yum.repos.d/下
CentOS-Stream(ansible-code).repo
二、使用pip安装
1、确保pip可用(以下可直接将python3 -m ->pip3)
python3 -m pip -V
如果一切正常,您应该会看到如下内容:
python3 -m pip -V
pip 21.0.1 from /usr/lib/python3.9/site-packages/pip (python 3.9) # python 3.8可行
如果您看到类似以下的错误No module named pip
,您需要安装pip
在您选择的Python解释器下。这可能意味着安装额外的操作系统包(例如,python3-pip
),或者安装最新的pip
通过运行以下命令,直接从Python打包中心获得:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --user
也可直接将pip更新(不建议)
pip3 install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
2、安装Ansible
使用pip
在您选择的Python环境中为当前用户安装您选择的Ansible包:
python3 -m pip install --user ansible -i https://pypi.tuna.tsinghua.edu.cn/simple
或者,您可以安装特定版本的ansible-core
在这个Python环境中:
python3 -m pip install --user ansible-core==2.13.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
3、升级Ansible
python3 -m pip install --upgrade --user ansible -i https://pypi.tuna.tsinghua.edu.cn/simple
(3)查看是否安装成功#ansible --version
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OfqiYEcU-1659436549873)(C:\Users\26807\AppData\Roaming\Typora\typora-user-images\image-20220802181622197.png)]
如果这个为3.6,直接卸载3.6,再安装ansible,再安回python36
简单测试一下ansible可不可用(保证被控主机有ssh,python)
vim /etc/ansible/hosts
[node]
node1.example.com
node2.example.com
在使用ansible node -m ping
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8wFhTNPw-1659436549874)(C:\Users\26807\AppData\Roaming\Typora\typora-user-images\image-20220802182926182.png)]
有就证明安装成功
边栏推荐
- callback prototype __proto__
- Wiring diagrams of switches, motors, circuit breakers, thermocouples, and meters
- sre成长之路
- Electrical diagram of power supply system
- 封装和包、访问修饰权限
- y85.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶、pushgateway和prometheus存储(十六)
- 解道9-编程技术6
- [C题目]力扣234. 回文链表
- Jar包启动通过ClassPathResource获取不到文件路径问题
- 信息学奥赛一本通(1260:【例9.4】拦截导弹(Noip1999))
猜你喜欢
随机推荐
Xcode13.1运行工程报错fatal error: ‘IFlyMSC/IFly.h‘ file not found的问题
Details in C# you don't know
golang刷leetcode: 在每个树行中找最大值
用了TCP协议,就一定不会丢包吗?
C primer plus学习笔记 —— 9、联合&枚举&typdef
Li Mu hands-on learning deep learning V2-bert and code implementation
golang刷leetcode:巫师的总力量和
.NET performance optimization - you should set initial size for collection types
华为设备配置BFD多跳检测
[21 Days Learning Challenge] Bubble Sort and Insertion Sort
How the sensor works
五大维度解读软件测试分类
ACE JET NPOI
y85.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶、pushgateway和prometheus存储(十六)
Digital twins help visualize the construction of smart cities
js如何获取浏览器缩放比例
Nervegrowold hands-on learning deep learning V2 - Bert pre training data set and code implementation
The Orsay in Informatics (1256: Bouquet for Algernon)
供电系统电气图
Mysql用户管理