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 there's 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',
]

 

内置变量如下:
hostvars
group_names
environment
groups
inventory_hostname
ansible_hostname
inventory_hostname_short


版本2,2
play_hosts 与 ansible_play_batch 一样,列出play中所有hosts
ansible_play_hosts

2.3
inventory_dir
playbook_dir

在role中还可以使用role_path

 

posted @ 2018-05-19 00:27  ishmaelwanglin  阅读(215)  评论(0编辑  收藏  举报