当前位置:网站首页>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組內的所有主機
边栏推荐
- acwing 843. N-queen problem
- Code source de la fonction [analogique numérique] MATLAB allcycles () (non disponible avant 2021a)
- Intel and Xinbu technology jointly build a machine vision development kit to jointly promote the transformation of industrial intelligence
- 史上最全学习率调整策略lr_scheduler
- MySQL数据库(基础篇)
- 全国气象数据/降雨量分布数据/太阳辐射数据/NPP净初级生产力数据/植被覆盖度数据
- In depth analysis of kubebuilder
- Up to 5million per person per year! Choose people instead of projects, focus on basic scientific research, and scientists dominate the "new cornerstone" funded by Tencent to start the application
- Advertising attribution: how to measure the value of buying volume?
- [practice leads to truth] is the introduction of import and require really the same as what is said on the Internet
猜你喜欢
【736. Lisp 语法解析】
5G VoNR+之IMS Data Channel概念
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
Common methods of list and map
A line of R code draws the population pyramid
Programmers go to work fishing, so play high-end!
Camera calibration (I): robot hand eye calibration
Markdown editor
Flex layout and usage
Time complexity & space complexity
随机推荐
广告归因:买量如何做价值衡量?
[Yugong series] go teaching course 005 variables in July 2022
Kivy tutorial of setting the size and background of the form (tutorial includes source code)
5G VoNR+之IMS Data Channel概念
Intel and Xinbu technology jointly build a machine vision development kit to jointly promote the transformation of industrial intelligence
Flask project uses flask socketio exception: typeerror: function() argument 1 must be code, not str
STM32F103实现IAP在线升级应用程序
npm ERR! 400 Bad Request - PUT xxx - “devDependencies“ dep “xx“ is not a valid dependency name
Acl2022 | decomposed meta learning small sample named entity recognition
Markdown编辑器
每人每年最高500万经费!选人不选项目,专注基础科研,科学家主导腾讯出资的「新基石」启动申报
A detailed explanation of head pose estimation [collect good articles]
Function pointer and pointer function in C language
【ArcGIS教程】专题图制作-人口密度分布图——人口密度分析
Appium practice | make the test faster, more stable and more reliable (I): slice test
Jetson nano configures pytorch deep learning environment / / to be improved
[Android kotlin collaboration] use coroutinecontext to realize the retry logic after a network request fails
Web3 社区中使用的术语
Terms used in the Web3 community
计数排序基础思路