我正在尝试枚举我的eth0
地址(设置为默认值,因为我在某处读到 eth0 并不总是可用..)。在我的模板中,我尝试像这样从组中调用它......
[Unit]
Description=Kubernetes Kube Proxy
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
[Service]
ExecStart=/usr/bin/kube-proxy \
--master=https://{{ groups[controller][0]['ansible_default_ipv4']['address'] }}:6443 \
--kubeconfig=/var/lib/kubelet/kubeconfig \
--proxy-mode=iptables \
--v=2
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
这似乎应该是可用的,因为当我倾倒时-debug var=groups
我得到......
[18.234.92.196] => {
"groups": {
......
"controller": [
"54.86.253.135",
"52.205.43.24",
"54.210.213.10"
],
"controller.0": [
"54.86.253.135"
],
"controller.1": [
"52.205.43.24"
],
"controller.2": [
"54.210.213.10"
],
......
"name_controller-0": [
"54.86.253.135"
],
"name_controller-1": [
"52.205.43.24"
],
"name_controller-2": [
"54.210.213.10"
],
......
}
}
奇怪的是,当我尝试调试时,var=groups[controller]
我得到...
TASK [worker : debug] *******************************************************************************************************************************************
ok: [34.207.172.100] => {
"groups[controller]": "VARIABLE IS NOT DEFINED!: 'controller' is undefined"
}
.....
TASK [worker : Add Kubelet configuration] ***********************************************************************************************************************
fatal: [34.207.172.100]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'controller' is undefined"}
我在这里想念什么?
想通了,需要先通过组指定IP并将其用作索引。
还有,
ansible_default_ipv4
好像不存在,所以换到public_ip
哪个是一样的东西。