1

Hi Im tried to automate different type of node groups in terraform to dynamically populate the inventory file with the config of instance tags and configs we pass in custom tfvars.

I was able to render the inventory file properly, However when I run ansible command over it, it fails with

TASK [bastion-ssh-config : create ssh bastion conf] fatal: [bastion]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_host'"}

below is my custom generated inventory file

[all]
ip-10-211-204-179.ap-south-1.compute.internal ansible_host=10.211.204.179
ip-10-211-222-187.ap-south-1.compute.internal ansible_host=10.211.222.187
ip-10-211-194-202.ap-south-1.compute.internal ansible_host=10.211.194.202
ip-10-211-207-181.ap-south-1.compute.internal ansible_host=10.211.207.181
ip-10-211-218-9.ap-south-1.compute.internal ansible_host=10.211.218.9
ip-10-211-199-118.ap-south-1.compute.internal ansible_host=10.211.199.118
ip-10-211-214-102.ap-south-1.compute.internal ansible_host=10.211.214.102
ip-10-211-194-189.ap-south-1.compute.internal ansible_host=10.211.194.189
ip-10-211-221-38.ap-south-1.compute.internal ansible_host=10.211.221.38
ip-10-211-205-11.ap-south-1.compute.internal ansible_host=10.211.205.11
bastion ansible_host=65.2.38.18
bastion ansible_host=15.206.90.177

[bastion]
bastion ansible_host=65.2.38.18
bastion ansible_host=15.206.90.177

[kube-master]
ip-10-211-204-179.ap-south-1.compute.internal
ip-10-211-222-187.ap-south-1.compute.internal
ip-10-211-194-202.ap-south-1.compute.internal


[kube-node]
ip-10-211-207-181.ap-south-1.compute.internal
ip-10-211-218-9.ap-south-1.compute.internal
ip-10-211-199-118.ap-south-1.compute.internal
ip-10-211-214-102.ap-south-1.compute.internal


[etcd]
ip-10-211-194-189.ap-south-1.compute.internal
ip-10-211-221-38.ap-south-1.compute.internal
ip-10-211-205-11.ap-south-1.compute.internal


[k8s-cluster:children]
kube-node
kube-master


[k8s-cluster:vars]
apiserver_loadbalancer_domain_name="kubernetes-elb-25tagversion-1844424666.ap-south-1.elb.amazonaws.com"

note: there is no change on ansible side as I believe the only link is the inventory file between terraform and ansible.

have tried with tag: 2.15

  • Where are you setting the `ansible_host` variable? Maybe you are trying to use `inventory_hostname`? Check the "magic variable" list here: https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html – cjnash Mar 30 '21 at 15:57

0 Answers0