当前位置:网站首页>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组内的所有主机
边栏推荐
- 【數模】Matlab allcycles()函數的源代碼(2021a之前版本沒有)
- Wechat can play the trumpet. Pinduoduo was found guilty of infringement. The shipment of byte VR equipment ranks second in the world. Today, more big news is here
- Factor analysis r practice (with R installation tutorial and code)
- Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry
- Markdown编辑器
- 深入解析Kubebuilder
- Vscode automatically adds a semicolon and jumps to the next line
- Tiktok may launch an independent grass planting community platform: will it become the second little red book
- Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
- Kivy tutorial of setting the size and background of the form (tutorial includes source code)
猜你喜欢
程序员上班摸鱼,这么玩才高端!
Camera calibration (I): robot hand eye calibration
Depth first traversal template principle of tree and graph
Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
指针与数组在函数中输入实现逆序输出
[line segment tree practice] recent requests + area and retrieval - array modifiable + my schedule I / III
DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
Decorator basic learning 02
Kivy tutorial of setting the size and background of the form (tutorial includes source code)
AI landing new question type RPA + AI =?
随机推荐
赠票速抢|行业大咖纵论软件的质量与效能 QECon大会来啦
Camera calibration (I): robot hand eye calibration
Web3 社区中使用的术语
ESG Global Leaders Summit | Intel Wang Rui: coping with global climate challenges with the power of science and technology
Servicemesh mainly solves three pain points
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
【实践出真理】import和require的引入方式真的和网上说的一样吗
File upload vulnerability summary
AI landing new question type RPA + AI =?
Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
Intel David tuhy: the reason for the success of Intel aoten Technology
C语言中函数指针与指针函数
一图看懂!为什么学校教了你Coding但还是不会的原因...
Talk about the importance of making it clear
Analyse approfondie de kubebuilder
5G VoNR+之IMS Data Channel概念
使用Thread类和Runnable接口实现多线程的区别
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
组织实战攻防演练的5个阶段
[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet