我在ansible的group_vars/all
文件中定义了一个变量。
overlay:True
我需要检查playbook中的内核版本,如果内核版本小于4,则将上面的varibale设置为false。可以在ansible中完成。 如果是,我想知道步骤/ ansible模块。
答案 0 :(得分:1)
According to http://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable
In 2.x, we have made the order of precedence more specific (with the last listed variables winning prioritization):
- role defaults [1]
- inventory file or script group vars [2]
- inventory group_vars/all
- playbook group_vars/all
- inventory group_vars/*
- playbook group_vars/*
- inventory file or script host vars [2]
- inventory host_vars/*
- playbook host_vars/*
- host facts
- play vars
- play vars_prompt
- play vars_files
- role vars (defined in role/vars/main.yml)
- block vars (only for tasks in block)
- task vars (only for the task)
- role (and include_role) params
- include params
- include_vars
- set_facts / registered vars
- extra vars (always win precedence)
set_fact
has the second higher precedence. So vars set by set_fact
should be able to override group vars.