myr*_*rdd 10 file-organization ansible ansible-role
在某些安全角色(例如roles/my-role/)中,我有一些很大的默认变量文件(defaults/main.yml).我想把它main.yml分成几个较小的文件.有可能吗?
我试图创建的文件defaults/1.yml和defaults/2.yml,但他们不会被加载ansible.
如果您不使用 2.6(您可能应该使用,但我知道这并不总是一个选项),那么您可能会发现include_vars 很有用。
- name: Include vars of stuff.yaml into the 'stuff' variable (2.2).
include_vars:
file: stuff.yaml
name: stuff
- name: Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2)
include_vars:
file: contingency_plan.yaml
name: plans
when: x == 0
- name: Load a variable file based on the OS type, or a default if not found. Using free-form to specify the file.
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- default.yaml
- name: Bare include (free-form)
include_vars: myvars.yaml
- name: Include all .json and .jsn files in vars/all and all nested directories (2.3)
include_vars:
dir: vars/all
extensions:
- json
- jsn
- name: Include all default extension files in vars/all and all nested directories and save the output in test. (2.2)
include_vars:
dir: vars/all
name: test
- name: Include default extension files in vars/services (2.2)
include_vars:
dir: vars/services
depth: 1
- name: Include only files matching bastion.yaml (2.2)
include_vars:
dir: vars
files_matching: bastion.yaml
Run Code Online (Sandbox Code Playgroud)
不过请注意,这是一个任务指令。它不像能够将它包含到默认文件本身那样简洁。
| 归档时间: |
|
| 查看次数: |
4782 次 |
| 最近记录: |