当前位置:网站首页>Ansible中的inventory主機清單(預祝你我有數不盡的鮮花和浪漫)
Ansible中的inventory主機清單(預祝你我有數不盡的鮮花和浪漫)
2022-07-07 04:57: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組內的所有主機
边栏推荐
- How does vscade use the built-in browser?
- How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
- STM32 encapsulates the one key configuration function of esp8266: realize the switching between AP mode and sta mode, and the creation of server and client
- STM32F103ZE+SHT30检测环境温度与湿度(IIC模拟时序)
- 01 machine learning related regulations
- Introduction to namespace Basics
- Break the memory wall with CPU scheme? Learn from PayPal to expand the capacity of aoteng, and the volume of missed fraud transactions can be reduced to 1/30
- PLC模拟量输出 模拟量输出FB analog2NDA(三菱FX3U)
- STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建
- Common Oracle SQL statements
猜你喜欢
Why do many people misunderstand technical debt
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
How does vscade use the built-in browser?
程序员上班摸鱼,这么玩才高端!
DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
MySQL forgot how to change the password
[Yugong series] go teaching course 005 variables in July 2022
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
随机推荐
Servicemesh mainly solves three pain points
Lecture 3 of "prime mover x cloud native positive sounding, cost reduction and efficiency enhancement lecture" - kubernetes cluster utilization improvement practice
Run the command once per second in Bash- Run command every second in Bash?
R language principal component PCA, factor analysis, clustering analysis of regional economy analysis of Chongqing Economic Indicators
Some understandings about 01 backpacker
JS input and output
Gpt-3 is a peer review online when it has been submitted for its own research
Fiance donated 500million dollars to female PI, so that she didn't need to apply for projects, recruited 150 scientists, and did scientific research at ease!
全国气象数据/降雨量分布数据/太阳辐射数据/NPP净初级生产力数据/植被覆盖度数据
Programmers go to work fishing, so play high-end!
Analyse approfondie de kubebuilder
Meaning of 'n:m' and '1:n' in database design
【736. Lisp 语法解析】
Break the memory wall with CPU scheme? Learn from PayPal to expand the capacity of aoteng, and the volume of missed fraud transactions can be reduced to 1/30
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
Pointer and array are input in function to realize reverse order output
Talk about the importance of making it clear
关于01背包个人的一些理解
装饰器基础学习02
使用Thread类和Runnable接口实现多线程的区别