I am trying to configure one set of hosts [nodes] using facts from another set of hosts [etcd]. Here is my hosts file
[master] kubernetes ansible_ssh_host=10.2.23.108 [nodes] n1 ansible_ssh_host=10.2.23.192 n2 ansible_ssh_host=10.2.23.47 [etcd] etcd01 ansible_ssh_host=10.2.23.11 etcd02 ansible_ssh_host=10.2.23.10 etcd03 ansible_ssh_host=10.2.23.9
Note that the group [etcd] is not the target of provisioning - [nodes] is. But provisioning [nodes] requires knowledge of the facts of [etcd].
Here is my playbook:
--- - name: Configure common hosts: nodes sudo: True tasks: - name: etcd endpoints file: dest=/etc/kubernetes state=directory - name: etcd endpoints template: src=files/k.j2 dest=/etc/kubernetes/apiserver
Finally, here is the template for files/k.j2
KUBE_ETCD_SERVERS="--etcd_servers="{% for host in groups['etcd'] %}https://{{hostvars[host]['ansible_eth0']["ipv4"]["address"]}}:2380{% if not loop.last %},{% endif %}{% endfor %}"
The goal is to produce a KUBE_ETCD_SERVERS value that looks like
--etcd_servers=https://10.2.23.11:2380,https://10.2.23.10:2380,https://10.2.23.10:2380
When I run this playbook I get console output
TASK [etcd endpoints] ********************************************************** fatal: [n1]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'ansible_eth0'"} fatal: [n2]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'ansible_eth0'"}
What is the idiomatic Ansible way to make the etcd facts available to the node play?
setup
module against one of the server and paste the output. May be it doesn't haveansible_eth0
– Arbab Nazareth0
on etcd. Or, once time i've become same error when changing iptables to firewalld (some depended packages were removed as 'unused') – A K