ansible-incentory主机清单

主机清单配置

ansible默认的主机清单是/etc/ansible/hosts文件

主机清单可以手动设置,也可以通过Dynamic Inventory动态生成
一般主机名使用FQDN(完全合格域名,如:www.baidu.com;域名为:baidu.com)

vi /etc/ansible/hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

## [webservers] #方括号设置组名
## alpha.example.org #定义被监控的主机,可以是主机名也可以是IP地址,主机名需要修改/etc/hosts文件
## beta.example.org
## 192.168.1.100
## 192.168.1.110
##www2.example.org:2222 #冒号后定义远程连接端口,默认是ssh的22端口

如果是名称类似的主机,可以使用列表的方式标识各个主机
[webserver]
www[01:50].example.org ansible_ssh_user=root ansible_ssh_pass=123456

[dbbservers]
db-[a:f].example.org 1/支持匹配a b c ... f

# If you have multiple hosts following a pattern you can specify
# 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 there are no
# leading 0s:

##

Inventory(库存)中变量

主机变量

[webserver]
www1.magedu.com http_port=80 maxRequestsChild=808
www2.magedu.com http_port=8080 maxRequestsChild=909

组变量

[servers:vars]
ntp_server=ntp.example.orgnfs_server=nfs.example.org

组嵌套

[apache]
http1.example.orghttp2.example.org

[nginx]
ngx1.example.org
ngx2.example.org

[webserver:children]
apache
nginx

inventory变量参数

参数说明
ansible_ssh_host将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置.
ansible_ssh_portssh端口号.如果不是默认的端口号,通过此变量设置.
ansible_ssh_user默认的ssh用户名
ansible_ssh_passssh密码(这种方式并不安全,我们强烈建议使用–ask-pass或 SSH 密钥)
ansible_ssh_private_key_filessh使用的私钥文件.适用于有多个密钥,而你不想使用 SSH代理的情况.ansible_ssh_common_args此设置附加到sftp,scp和ssh的缺省命令行
ansible_sftp_extra_args此设置附加到默认sftp命令行。
ansible_scp_extra_args此设置附加到默认scp命令行。
ansible_ssh_extra_args此设置附加到默认ssh命令行。
ansible_ssh_pipelining确定是否使用SSH管道。这可以覆盖ansible.cfg中得设置。
ansible_shell_type目标系统的shell类型.默认情况下,命令的执行使用’sh’语法,可设置为‘csh’或’fish’.
ansible_python interpreter目标主机的 python路径.适用于的情况:系统中有多个Python,或者命令路径不是"/usr/bin/python’
ansible_*_interpreter这里的"*"可以是ruby 或perl 或其他语言的解释器,作用和ansible_python interpreter类似
ansible_shell_executable这将设置ansible控制器将在目标机器上使用的shell,覆盖ansible.cfg中的配置,默认为/bin/sh。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值