剑客Ansible拔剑--YAML语言与Inventory主机清单

时间:2018-08-06 18:24:27   收藏:0   阅读:169
YAML介绍
(1)、具有很好的可读性,易于实现;
(2)、表达能力强,扩展性好;
(3)、和脚本语言的交互性较好;
(4)、有一个一致的信息模型;
(5)、可以基于流来处理

1、YAML语法

2、常用的数据类型

1)、list

- Apple
- Orange
- Strawberry
- Mango

2)、dictionary

name: Example Developer
Job: Developer
Skill:Elite
{name: Example Developer,Job: Developer,Skill:Elite}

Inventory主机清单

[webserver]      #方括号设置组名
www1.test.org    #定义被监控主机,这边可以是主机名也可以是IP地址,主机名需要修改/etc/hosts文件
www2.test.org:2222     #冒号后定义远程连接端口,默认是ssh的2222端口
[webserver]
www[01:50].test.org ansible_ssh_user=root ansible_ssh_pass=123456    #支持01到50,用户为root,密码为123456
[dbbservers]
db-[a:f].test.org        #支持匹配a b c ... f

在Inventory中有几个重要的概念

[webserver]
www1.test.com http_port=80 maxRequestsChild=808
www2.test.com http_port=8080 maxRequestsChild=909
[servers:vars]
ntp_server=ntp.test.org
nfs_server=nfs.test.org
[apache]
http1.test.org
http2.test.org

[nginx]
ngx1.test.org
ngx2.test.org

[webservers:children]
apache
nginx
参数 说明
ansible_ssh_host 将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置.
ansible_ssh_port ssh端口号.如果不是默认的端口号,通过此变量设置.
ansible_ssh_user 默认的 ssh 用户名
ansible_ssh_pass ssh 密码(这种方式并不安全,我们强烈建议使用 --ask-pass 或 SSH 密钥)
ansible_ssh_private_key_file ssh 使用的私钥文件.适用于有多个密钥,而你不想使用 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",比如 *BSD, 或者 /usr/bin/python
ansible_*_interpreter 这里的"*"可以是ruby 或perl 或其他语言的解释器,作用和ansible_python_interpreter 类似
ansible_shell_executable 这将设置ansible控制器将在目标机器上使用的shell,覆盖ansible.cfg中的配置,默认为/bin/sh。
[websers]
192.168.100.1 ansible_ssh_user=root ansible_ssh_pass=123456     #IP地址、用户、密码

原文:http://blog.51cto.com/13659182/2155416

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!