当前位置:网站首页>Ansible中的inventory主机清单(预祝你我有数不尽的鲜花和浪漫)
Ansible中的inventory主机清单(预祝你我有数不尽的鲜花和浪漫)
2022-07-06 22:36:00 【Steve lu】
前言
本篇博客主要解释Ansible主机清单的相关配置知识
一、inventory 主机清单

Inventory支持对主机进行分组,每个组内可以定义多个主机,每个主机都可以定义在任何一个或多个主机组内。
如果是名称类似的主机,可以使用列表的方式表示各个主机
vim /etc/ansible/hosts
[dbservers]
192.168.109.131:2222 #冒号后定义远程连接端口,默认是ssh的22端口
192.168.109.13[1:3] #范围是:192.168.109.131到192.168.109.133
[[email protected] ansible]# ansible dbservers -a 'date'
192.168.109.133 | CHANGED | rc=0 >>
2022年 07月 06日 星期三 14:43:18 CST
192.168.109.132 | CHANGED | rc=0 >>
2022年 07月 06日 星期三 14:43:18 CST
192.168.109.131 | CHANGED | rc=0 >>
2022年 07月 06日 星期三 14:43:18 CST
[dbservers]
db-[a:f].example.org #支持主机名匹配 a~f


1.1 inventory 中的变量
| Inventory变量名 | 含义 |
|---|---|
| ansible_host | ansible连接节点时的IP地址 |
| ansible_port | 连接对方的端口号,ssh连 接时默认为22 |
| ansible_user | 连接对方主机时使用的主机名。不指定时,将使用执行ansible或ansible-playbook命令的用户 |
| ansible_passwd | 连接时的用户的ssh密码,仅在未使用密钥对验证的情况下有效 |
| ansible_ssh_private_key_file | 指定密钥认证ssh连接时的私钥文件 |
| ansible_ssh_common_args | 提供给ssh、sftp、 scp命 令的额外参数 |
| ansible_become | 允许进行权限提升 |
| ansible_become_method | 指定提升权限的方式,例如可使用sudo/su/runas等方式 |
| ansible_become_user | 提升为哪个用户的权限,默认提升为root |
| ansible_become_password | 提升为指定用户权限时的密码 |
1.2 主机变量
#修改被管理客户端192.168.109.134 ssh配置文件17行修改端口号
systemctl stop firewalld.service
setenforce 0
vim /etc/ssh/sshd_config
Port 2222
systemctl restart sshd
#这台客户端我没有配置免密登录
#修改Ansible管理服务器主机清单配置文件
vim /etc/ansible/hosts
[lhq]
192.168.109.134 ansible_port=2222 ansible_user=root ansible_password=123123
#不建立将密码直接写入配置,不安全
ansible dbservers -a 'date'



1.3 组变量
#删除客户端已有的免密登录密钥文件
#客户端配置
cd
cd .ssh/
rm -rf authorized_keys
#ansible控制端配置
vim /etc/ansible/hosts
[webservers]
192.168.109.131
192.168.109.132
192.168.109.133
[webservers:vars]
#表示为 webservers 组内所有主机定义变量
ansible_user=root
ansible_password=123456
[[email protected] ansible]# ansible webservers -a 'date'
192.168.109.132 | CHANGED | rc=0 >>
2022年 07月 06日 星期三 17:34:46 CST
192.168.109.134 | CHANGED | rc=0 >>
2022年 07月 06日 星期三 17:34:46 CST
192.168.109.133 | CHANGED | rc=0 >>
2022年 07月 06日 星期三 17:34:46 CST
192.168.109.131 | CHANGED | rc=0 >>
2022年 07月 06日 星期三 17:34:46 CST


1.4 组嵌套
vim /etc/ansible/hosts
[webservers]
192.168.239.20
192.168.239.30
192.168.239.40
[webservers:vars]
ansible_user=root
ansible_password=1999612
[dbservers]
192.168.239.50:2222 ansible_user=root ansible_password=1999612
[webservers1:children]
webservers
dbserers
#表示为 webservers1 主机组中包含了webservers组和dbservers组内的所有主机


边栏推荐
- 两个div在同一行,两个div不换行「建议收藏」
- 关于01背包个人的一些理解
- Gpt-3 is a peer review online when it has been submitted for its own research
- 【愚公系列】2022年7月 Go教学课程 005-变量
- Acl2022 | decomposed meta learning small sample named entity recognition
- System framework of PureMVC
- STM32F103ZE+SHT30检测环境温度与湿度(IIC模拟时序)
- 5G VoNR+之IMS Data Channel概念
- A line of R code draws the population pyramid
- Introduction to the PureMVC series
猜你喜欢

namespace基础介绍

Common methods of list and map

Kivy tutorial of setting the size and background of the form (tutorial includes source code)
![Local tool [Navicat] connects to remote [MySQL] operation](/img/e8/a7533bac4a70ab5aa3fe15f9b0fcb0.jpg)
Local tool [Navicat] connects to remote [MySQL] operation

Oracle - views and sequences

How to package the parsed Excel data into objects and write this object set into the database?

为什么很多人对技术债务产生误解

九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」

Decorator basic learning 02

A line of R code draws the population pyramid
随机推荐
You can't sell the used lithography machine to China! The United States unreasonably pressured the Dutch ASML, and domestic chips were suppressed again
全国气象数据/降雨量分布数据/太阳辐射数据/NPP净初级生产力数据/植被覆盖度数据
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
Markdown editor
Advertising attribution: how to measure the value of buying volume?
B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
程序员上班摸鱼,这么玩才高端!
使用Thread类和Runnable接口实现多线程的区别
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
sscanf,sscanf_ S and its related usage "suggested collection"
Tiktok may launch an independent grass planting community platform: will it become the second little red book
Meaning of 'n:m' and '1:n' in database design
MySQL数据库(基础篇)
Is there any way to bookmark the code in the visual studio project- Is there a way to bookmark code in a Visual Studio project?
[line segment tree practice] recent requests + area and retrieval - array modifiable + my schedule I / III
A picture to understand! Why did the school teach you coding but still not
namespace基础介绍
【數模】Matlab allcycles()函數的源代碼(2021a之前版本沒有)
ServiceMesh主要解决的三大痛点
广告归因:买量如何做价值衡量?