这个文件是ansible的inventory文件
filetypedetect BufNewFile
*.pysetf python
filetypedetect BufRead
*.pysetf python
Press ENTER or type command to continue
[root@node110 ansible]# cat hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
# - Commentsbegin with the '#' character
# - Blank linesare ignored
# - Groups ofhosts are delimited by [header] elements
# - You can enterhostnames or ip addresses
# - A hostname/ipcan be a member of multiple groups
# Ex 1: Ungrouped hosts, specify before any groupheaders.
## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10
192.168.2.120
192.168.2.121
#192.168.2.225:52113
mysql_master ansible_ssh_port=52113ansible_ssh_host=192.168.2.225
# Ex 2: A collection of hosts belonging to the'webservers' group
ansible_ssh_host:指定主机别名对应的真实 IP,如:251ansible_ssh_host=183.60.41.251,
随后连接该主机无须指定完整 IP,只需指定 251 就行
ansible_ssh_port:指定连接到这个主机的 ssh 端口,默认 22
ansible_ssh_user:连接到该主机的 ssh 用户
ansible_ssh_pass:连接到该主机的 ssh 密码(连-k 选项都省了),安全考虑还是建议使用私钥
或在命令行指定-k 选项输入
ansible_sudo_pass:sudo 密码
ansible_sudo_exe(v1.8+的新特性):sudo 命令路径
ansible_connection:连接类型,可以是 local、ssh 或 paramiko,ansible1.2之前默认为 param
iko
ansible_ssh_private_key_file:私钥文件路径
ansible_shell_type:目标系统的 shell 类型,默认为 sh,如果设置 csh/fish,那么命令需要遵循
它们语法
ansible_python_interpreter:python 解释器路径,默认是/usr/bin/python,但是如要要连*BSD
系统的话,就需要该指令修改 python 路径
mysql_master ansible_ssh_port=52113ansible_ssh_host=192.168.2.225 ansible_python_interpreter=/usr/bin/python2.6 #这个目录要与客户端的路径一样
Ansible 中文手册 -By Geekwolf http://www.simlinux.com
10
ansible_*_interpreter:这里的"*"可以是 ruby 或 perl 或其他语言的解释器,作用和ansible_p
ython_interpreter 类似
例如:
some_host ansible_ssh_port=2222ansible_ssh_user=manager
aws_hostansible_ssh_private_key_file=/home/example/.ssh/aws.pem
freebsd_host ansible_python_interpreter=/usr/local/bin/python
ruby_module_hostansible_ruby_interpreter=/usr/bin/ruby.1.9.3
为每个主机指定连接类型和连接用户:
[targets]
localhost ansible_connection=local
other1.example.com ansible_connection=sshansible_ssh_user=mpdehaan
other2.example.com ansible_connection=sshansible_ssh_user=mdehaan
[webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110
192.168.2.120
192.168.2.121
# If you have multiple hosts following a pattern you canspecify
# them like this:
## www[001:006].example.com
# Ex 3: A collection of database servers in the'dbservers' group
## [dbservers]
##
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57
# Here's another example of host ranges, this time thereare no
# leading 0s:
## db-[99:101]-node.example.com
mail.example.com[webservers]
Foo.example.com
Bar.example.com
[dbservers]
One.example.com
Two.example.com
three.example.com
badwolf.example.com:5309 指定 SSH 端口 5309
jumper ansible_ssh_port=5555ansible_ssh_host=192.168.1.50 设置主机别名为 jumper
www[01:50].example.com 支持通配符匹配 www01 www02 ...www50
[databases]
db-[a:f].example.com 支持字母匹配 a b c...f
可以为每个主机单独指定一些变量,这些变量随后可以在 playbooks 中使用:
[atlanta]
host1 http_port=80 maxRequestsPerChild=808
host2 http_port=303 maxRequestsPerChild=909
也可以为一个组指定变量,组内每个主机都可以使用该变量:
[atlanta]
host1
host2
[atlanta:vars]
ntp_server=ntp.atlanta.example.com
proxy=proxy.atlanta.example.com
组可以包含其他组:
[atlanta]
host1
host2
[raleigh]
host2
host3
[southeast:children]
atlanta
raleigh
[southeast:vars]
some_server=foo.southeast.example.com
halon_system_timeout=30
self_destruct_countdown=60
escape_pods=2
[usa:children]
southeast
northeast
southwest
northwest
[]表示主机的分组名,可以按照功能、系统等进行分类,便于对某些主机或者某一组功能相同的主机进行操作