YAML:另外一种标记语言。是用来写配置文件的语言,很是简洁和强大。
YAML语法和其余语言相似,也能够表达散列表、标量等数据结构。
结构经过空格来展现;序列里配置项经过-来表明;Map里键值用:来分隔;YAML的扩展名为yamlpython
1.对象:键值对的集合,又称为映射(mapping)/ 哈希(hashes) / 字典(dictionary)
例如:name:Example Developer
键 值nginx2.数组:一组按次序排列的值,又称为序列(sequence) / 列表(list)
例如:-Apple
-Orangeweb3.纯量:单个的、不可再分的值
例如:number:12.30
sure:trueshellansible基本元素
ansible默认的主机清单是/etc/ansible/hosts文件
主机清单能够手动设置,也能够经过Dynamic Inventory动态生成
通常主机名使用FQDNapache
vim /etc/ansible/hosts [webserver] #方括号设置组名 www1.example.org #定义被监控主机,这边能够是主机名也能够是IP地址,主机名须要修改/etc/hosts文件 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 //支持匹配a b c ... f
Inventory中变量 (1)主机变量 [webserver] www1.magedu.com http_port=80 maxRequestsChild=808 www2.magedu.com http_port=8080 maxRequestsChild=909 (2)组变量 [servers:vars] ntp_server=ntp.example.org nfs_server=nfs.example.org (3)组嵌套 [apache] http1.example.org http2.example.org [nginx] ngx1.example.org ngx2.example.org [webservers:children] #组变量等于说当调用了 webservers:children 等于调用了四个服务 apache nginx #组变量等于说当调用了 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。 |