ansible--inventory主机清单以及ansible--playbook剧本

主机清单

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

vi /etc/ansible/hosts
[webserver]             #方括号中设置组名
www1.example.org        #定义被监控主机,这边可以是主机名也可以是IP地址
www2.example.org:2222   #冒号后面定义远程连接端口,默认是ssh的22端口

如果是名称类似的主机,可以使用列表的方式标识各个主机

[webserver]
www[01:50].example.org ansible_ssh_user=root ansible_ssh_pass=1

[dbservers]
db-[a:f].example.org   #支持匹配a、b、c.....f

(1)、主机变量

下面是Inventory中变量

[webserver]
www1.magedu.com http_port=80 maxRequestsCgild=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]
apache
nginx

(4)、inventor 变量参数

参数 说明
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”
ansible_*_interpreter 这里的*可以是ruby或perl或其他语言的解释器,作用和ansible_python_interpreter类似
ansible_shell_executable 这将设置ansible控制器将在目标机器上使用的shell,覆盖ansible.cfg中的配置,默认为/bin/sh

YAML文件

(一)、YAML基本语法规则

1、大小写敏感
2、使用缩进表示层级关系
3、缩进时不允许使用Tab键,只允许使用空格。
4、缩进的空格数目不重要,只要相同层级的元素左侧对齐即可

(二)、YAML支持的数据结构

1、对象:键值对的集合,又称为映射(mapping)/ 哈希(hashes)/ 字典(dictionary)

例如: name:Example Developer

2、数组:一

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值