ansible变量

Posted Lin.Wang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible变量相关的知识,希望对你有一定的参考价值。

变量的加载优先级如下:    
The order of precedence is: - play->roles->get_default_vars (if there is a play context) - group_vars_files[host] (if there is a host context) - host_vars_files[host] (if there is a host context) - host->get_vars (if there is a host context) - fact_cache[host] (if there is a host context) - play vars (if there is a play context) - play vars_files (if theres no host context, ignore file names that cannot be templated) - task->get_vars (if there is a task context) - vars_cache[host] (if there is a host context) - extra vars

 

hostvars:

STATIC_VARS = [
    ansible_version,
    ansible_play_hosts,
    inventory_hostname,
    inventory_hostname_short,
    inventory_file,
    inventory_dir,
    groups,
    group_names,
    omit,
    playbook_dir,
    play_hosts,
    role_names,
    ungrouped,
]

 

以上是关于ansible变量的主要内容,如果未能解决你的问题,请参考以下文章

ansible

1. ansible-playbook 变量定义与引用

尝试在ansible playbook中使用变量文件中的变量

ansible常用的定义变量方式和变量注册facts缓存和template的使用

ansible笔记(14):变量(一)

如何创建片段以重复变量编号中的代码行