您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页ansible介绍、安装及使用方法(1)

ansible介绍、安装及使用方法(1)

来源:伴沃教育

ansible的简介

ansible是一款批量部署的软件,可以实现同时对成百上千台服务器的同步管理,执行相关任务,也可编写脚本(playbook),提高代码的复用性。ansible还有幂等性,即重复运行playbook,检测到相同的操作或在任务已执行成功的机器不会再次运行。

原理:ansible通过使用sshd服务远程连接管理,所以受管机必须打开sshd服务,而且只需要在控制端安装ansible-core即可。

案例环境:Red Hat Enterprise Linux 9.1(linux系统的一个发行版本)
软件版本:ansible-core-2.13.3-1.el9.x86_

提示:未展开描述之处,建议询问AI辅助解答

软件包的安装

sudo dnf -y install ansible-core

配置/etc/hosts文件

vim /etc/hosts
172.25.0.100 control.lab0.example.com control con
172.25.0.101 node1.lab0.example.com node1 n1
172.25.0.102 node2.lab0.example.com node2 n2
172.25.0.103 node3.lab0.example.com node3 n3
172.25.0.104 node4.lab0.example.com node4 n4
172.25.0.105 node5.lab0.example.com node5 n5

配置清单文件inventory

vim inventory
[test01]
node1
[test02]
node2
[web]
node3
node4
[test05]
node5
[webtest:children]
web

配置ansible.cfg

vim ansible.cfg

[defaults]
inventory=./inventory
remote_user=alice
roles_path=/home/alice/ansible/roles
collections_path=/home/alice/ansible/collections

[privilege_escalation]
become=True
become_ask_pass=False
become_user=root
become_method=sudo

测试配置结果

ansible all -m ping # 无任何报错即可

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务