当前位置:网站首页>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組內的所有主機


边栏推荐
- Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
- How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
- 九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
- Basic idea of counting and sorting
- MySQL数据库(基础篇)
- Advertising attribution: how to measure the value of buying volume?
- acwing 843. n-皇后问题
- DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
- Run the command once per second in Bash- Run command every second in Bash?
- If you ask me about R code debugging, I will tell you head, STR, help
猜你喜欢

JDBC link Oracle reference code

Oracle -- 视图与序列

【实践出真理】import和require的引入方式真的和网上说的一样吗

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

acwing 843. n-皇后问题
![[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet](/img/58/4337f0972f7171a5c21e640f03e0b7.png)
[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet

Analyse approfondie de kubebuilder

Chapter 9 Yunji datacanvas company won the highest honor of the "fifth digital finance innovation competition"!

Markdown编辑器

【愚公系列】2022年7月 Go教学课程 005-变量
随机推荐
装饰器基础学习02
Lecture 3 of "prime mover x cloud native positive sounding, cost reduction and efficiency enhancement lecture" - kubernetes cluster utilization improvement practice
Servicemesh mainly solves three pain points
程序员上班摸鱼,这么玩才高端!
DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
File upload vulnerability summary
STM32F103实现IAP在线升级应用程序
Leetcode notes
Time complexity & space complexity
Talk about the importance of making it clear
关于01背包个人的一些理解
JS variable plus
Jetson nano configures pytorch deep learning environment / / to be improved
Meaning of 'n:m' and '1:n' in database design
How does vscade use the built-in browser?
《原动力 x 云原生正发声 降本增效大讲堂》第三讲——Kubernetes 集群利用率提升实践
5G VoNR+之IMS Data Channel概念
AttributeError: module ‘torch._C‘ has no attribute ‘_cuda_setDevice‘
JS input and output
窗口可不是什么便宜的东西