Я ищу поставить 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
Error
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
EDIT
- 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