ansible注意事项,


1、变量名称只能使用小写字母、数字和下划线,并且只能以小写字母开头
2、变量内容用引号引起来

变量规范:
变量只定义在三个地方,减少变量的管理:

role defaults,定义role中的默认变量(全局)
group/all  (组生效或全局生效)
命令行 vars (全局)

变量不能重复,不能含特殊字符,辨识度高,需要遵守变量的优先级
尽可能多的使用facts变量,来针对不同类型机器

变量优先级:

* extra vars (-e in the command line) always win
* then comes connection variables defined in inventory (ansible_ssh_user, etc)
* then comes "most everything else" (command line switches, vars in play, included vars, role vars, etc)
* then comes the rest of the variables defined in inventory
* then comes facts discovered about a system
* then "role defaults", which are the most "defaulty" and lose in priority to everything.
 
* extra vars (在命令行中使用 -e)优先级最高
* 然后是在inventory中定义的连接变量(比如ansible_ssh_user)
* 接着是大多数的其它变量(命令行转换,play中的变量,included的变量,role中的变量等)
* 然后是在inventory定义的其它变量
* 然后是由系统发现的facts
* 然后是 "role默认变量", 这个是最默认的值,很容易丧失优先权

相关内容

    暂无相关文章