I'm trying to run the playbook
ansible-playbook -i inventory/preprod/inventory.ini --private-key ~/.ssh/id_rsa_stagging -u cloud-user --become --become-user=root cluster.yml --tags resolvconf
And it returns this error:
fatal: [tivit-aiops-k8s-preprd-app-1]: FAILED! => {"msg": "The field 'environment' has an invalid value, which includes an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_hostname'"}
fatal: [tivit-aiops-k8s-preprd-app-2]: FAILED! => {"msg": "The field 'environment' has an invalid value, which includes an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_hostname'"}
fatal: [tivit-aiops-k8s-preprd-app-4]: FAILED! => {"msg": "The field 'environment' has an invalid value, which includes an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_hostname'"}
fatal: [tivit-aiops-k8s-preprd-app-3]: FAILED! => {"msg": "The field 'environment' has an invalid value, which includes an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_hostname'"}
fatal: [tivit-aiops-k8s-preprd-master-1]: FAILED! => {"msg": "The field 'environment' has an invalid value, which includes an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_hostname'"}
I don't understand what I'm doing wrong ....
Take a look at the sample inventory provided from Kubespray:
# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
# ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value.
[all]
# node1 ansible_host=95.54.0.12 # ip=10.3.0.1 etcd_member_name=etcd1
# node2 ansible_host=95.54.0.13 # ip=10.3.0.2 etcd_member_name=etcd2
# node3 ansible_host=95.54.0.14 # ip=10.3.0.3 etcd_member_name=etcd3
# node4 ansible_host=95.54.0.15 # ip=10.3.0.4 etcd_member_name=etcd4
# node5 ansible_host=95.54.0.16 # ip=10.3.0.5 etcd_member_name=etcd5
# node6 ansible_host=95.54.0.17 # ip=10.3.0.6 etcd_member_name=etcd6
There's a name which can be used to reference this host through the inventory file (for assigning groups to the host), and there's also an ansible_host
value which specifies the IP that Ansible will connect to (separately from the name).