Variables are divided into static variables (defined before execution) and dynamic variables (generated during execution). Priority: Dynamic variables > Static variables.
Includes: inventory, global config, and parameters defined in templates. Priority: Global config > Inventory > Parameters defined in templates.
YAML format, does not support template syntax. Passed via -i (kk -i inventory.yaml ...), effective on each host.
Specification Example:
apiVersion: kubekey.kubesphere.io/v1
kind: Inventory
metadata:
name: default
spec:
hosts:
hostname1:
k1: v1
hostname2:
k2: v2
hostname3: {}
groups:
groupname1:
groups:
- groupname2
hosts:
- hostname1
vars:
k1: v1
groupname2: {}
vars:
k1: v1| Field | Description |
|---|---|
| hosts | Key is host name, value is variables for that host. |
| groups | Group hosts. Key is group name, value contains groups, hosts, vars. groups are nested groups, hosts are hosts included in the group, vars are group variables that apply to all hosts in the group. Host set in group = hosts in groups ∪ hosts in hosts. |
| vars | Global variables, apply to all hosts. |
Variable priority: Host variables > Group variables > Global variables.
YAML format, does not support template syntax. Passed via -c (kk -c config.yaml ...), effective on each host.
apiVersion: kubekey.kubesphere.io/v1
kind: Config
metadata:
name: default
spec:
k: vAny key-value can be defined under spec, participating in variable resolution along with inventory.
Includes:
vars,vars_filesof playbookdefaults/main.yml,varsof rolevarsof task
Generated at runtime, includes:
- gather_facts gathered host information
- register registered task output
- set_fact set variables
With the same name, later definitions override earlier ones.