我想把一个ip放在变量中传递到一个模板中,不幸的是,有什么地方把这个变量的注册搞砸了?
- name: Get Controller[0] ip
command: "cat {{ controller0 }} |grep -A1 controller0 |tail -1 |awk '{print$2}'"
register: controller0
with_file:
- "{{ playbook_dir }}/../ssh.cfg"
- debug: var=controller0错误
fatal: [100.24.12.41]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'controller0' is undefined
The error appears to have been in '~/Terraform/terraform-kubernetes/ansible/roles/worker/tasks/main.yml': line 110, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Get the file contents
^ here
"}当地grep输出
$ cat ssh.cfg |grep -A1 controller0 |tail -1 |awk '{print$2}'
35.171.150.231 模板是
[Unit]
Description=Kubernetes Kube Proxy
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
[Service]
ExecStart=/usr/bin/kube-proxy \
--master=https://{{ controller0 }}:6443 \
--kubeconfig=/var/lib/kubelet/kubeconfig \
--proxy-mode=iptables \
--v=2
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target编辑
- name: Get the file contents
command: "echo -ne '{{ item }}' |grep -A1 controller0 |tail -1 |awk '{print$2}'"
with_file:
- "{{playbook_dir}}/../ssh.cfg"
register: controller
- debug: var=controller发布于 2018-11-08 01:36:16
弄明白了
- name: Get the file contents
shell: "echo -ne '{{ item }}' |grep -A1 controller0 |tail -1 |awk '{print$2}'"
with_file:
- "{{playbook_dir}}/../ssh.cfg"
register: controllerhttps://stackoverflow.com/questions/53199944
复制相似问题