当前位置:网站首页>Inventory host list in ansible (I wish you countless flowers and romance)
Inventory host list in ansible (I wish you countless flowers and romance)
2022-07-07 04:57:00 【Steve lu】
List of articles
Preface
This blog mainly explains Ansible Related configuration knowledge of host list
One 、inventory Host list

Inventory Support grouping hosts , Multiple hosts can be defined in each group , Each host can be defined in any one or more host groups .
If it's a host with a similar name , You can use a list to represent each host
vim /etc/ansible/hosts
[dbservers]
192.168.109.131:2222 # Define the remote connection port after the colon , The default is ssh Of 22 port
192.168.109.13[1:3] # The scope is :192.168.109.131 To 192.168.109.133
[[email protected] ansible]# ansible dbservers -a 'date'
192.168.109.133 | CHANGED | rc=0 >>
2022 year 07 month 06 Japan Wednesday 14:43:18 CST
192.168.109.132 | CHANGED | rc=0 >>
2022 year 07 month 06 Japan Wednesday 14:43:18 CST
192.168.109.131 | CHANGED | rc=0 >>
2022 year 07 month 06 Japan Wednesday 14:43:18 CST
[dbservers]
db-[a:f].example.org # Host name matching is supported a~f


1.1 inventory The variables in the
| Inventory Variable name | meaning |
|---|---|
| ansible_host | ansible When connecting nodes IP Address |
| ansible_port | The port number of the other party ,ssh even It defaults to 22 |
| ansible_user | The host name used when connecting to the other host . When not specified , Will use to execute ansible or ansible-playbook Users of commands |
| ansible_passwd | The name of the user when connecting ssh password , Valid only if key pair authentication is not used |
| ansible_ssh_private_key_file | Specify key authentication ssh Private key file when connecting |
| ansible_ssh_common_args | Provide to ssh、sftp、 scp life Make additional parameters |
| ansible_become | Permission escalation is allowed |
| ansible_become_method | Specify how to raise permissions , For example, you can use sudo/su/runas Methods such as |
| ansible_become_user | To which user , Default promotion is root |
| ansible_become_password | The password when promoting to the specified user permission |
1.2 Host variables
# Modify the managed client 192.168.109.134 ssh The configuration file 17 Line to modify the port number
systemctl stop firewalld.service
setenforce 0
vim /etc/ssh/sshd_config
Port 2222
systemctl restart sshd
# I haven't configured password free login for this client
# modify Ansible Manage the server host inventory configuration file
vim /etc/ansible/hosts
[lhq]
192.168.109.134 ansible_port=2222 ansible_user=root ansible_password=123123
# Write the password directly to the configuration without establishing , unsafe
ansible dbservers -a 'date'



1.3 Group variable
# Delete the existing password free login key file of the client
# Client configuration
cd
cd .ssh/
rm -rf authorized_keys
#ansible Configuration of control end
vim /etc/ansible/hosts
[webservers]
192.168.109.131
192.168.109.132
192.168.109.133
[webservers:vars]
# Expressed as webservers All hosts in the group define variables
ansible_user=root
ansible_password=123456
[[email protected] ansible]# ansible webservers -a 'date'
192.168.109.132 | CHANGED | rc=0 >>
2022 year 07 month 06 Japan Wednesday 17:34:46 CST
192.168.109.134 | CHANGED | rc=0 >>
2022 year 07 month 06 Japan Wednesday 17:34:46 CST
192.168.109.133 | CHANGED | rc=0 >>
2022 year 07 month 06 Japan Wednesday 17:34:46 CST
192.168.109.131 | CHANGED | rc=0 >>
2022 year 07 month 06 Japan Wednesday 17:34:46 CST


1.4 Group nesting
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
# Expressed as webservers1 The host group contains webservers Group and dbservers All hosts in the group


边栏推荐
- R language principal component PCA, factor analysis, clustering analysis of regional economy analysis of Chongqing Economic Indicators
- A simple and beautiful regression table is produced in one line of code~
- 微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
- Local tool [Navicat] connects to remote [MySQL] operation
- Comparison between thread and runnable in creating threads
- 抖音或将推出独立种草社区平台:会不会成为第二个小红书
- A detailed explanation of head pose estimation [collect good articles]
- PLC Analog output analog output FB analog2nda (Mitsubishi FX3U)
- C语言中函数指针与指针函数
- Lecture 3 of "prime mover x cloud native positive sounding, cost reduction and efficiency enhancement lecture" - kubernetes cluster utilization improvement practice
猜你喜欢

【Android Kotlin协程】利用CoroutineContext实现网络请求失败后重试逻辑

Markdown编辑器

Time complexity & space complexity

MySQL数据库(基础篇)

namespace基础介绍

深入解析Kubebuilder

In depth analysis of kubebuilder

如何设计 API 接口,实现统一格式返回?

Oracle - views and sequences
![[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
随机推荐
How to package the parsed Excel data into objects and write this object set into the database?
Intel David tuhy: the reason for the success of Intel aoten Technology
什么是Web3
Lessons and thoughts of the first SQL injection
Gpt-3 is a peer review online when it has been submitted for its own research
Ansible报错:“msg“: “Invalid/incorrect password: Permission denied, please try again.“
JS variable plus
MySQL forgot how to change the password
Talk about the importance of making it clear
当 Knative 遇见 WebAssembly
窗口可不是什么便宜的东西
The worse the AI performance, the higher the bonus? Doctor of New York University offered a reward for the task of making the big model perform poorly
组织实战攻防演练的5个阶段
R language principal component PCA, factor analysis, clustering analysis of regional economy analysis of Chongqing Economic Indicators
Leetcode notes
DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
npm ERR! 400 Bad Request - PUT xxx - “devDependencies“ dep “xx“ is not a valid dependency name
Stm32f103ze+sht30 detection of ambient temperature and humidity (IIC simulation sequence)
[Yugong series] go teaching course 005 variables in July 2022
Thread和Runnable创建线程的方式对比