Hi All,
I’m trying to figure what’s the best way to set my web servers hostname in Amazon EC2 and also have them configured in the HA Proxy config automatically by Ansible.
I have the following inventory file :
Hi All,
I’m trying to figure what’s the best way to set my web servers hostname in Amazon EC2 and also have them configured in the HA Proxy config automatically by Ansible.
I have the following inventory file :
Hi Nicolas,
[‘.ansible_hostname’] should be:
[‘ansible_hostname’] or [‘ansible_fqdn’] as appropriate.
Does that help?
well spotted lwade , it did help !
regarding the hostname set running the tasks bellow I have my inventory file like this :
[webservers]
ec2-46-51-135-172.eu-west-1.compute.amazonaws.com hostname=web1.eu-west
ec2-54-216-118-162.eu-west-1.compute.amazonaws.com hostname=web2.eu-west
ec2-54-216-99-20.eu-west-1.compute.amazonaws.com hostname=web3.eu-west
unfortunately the hostname has been set to ${hostname} by the tasks instead of web1.eu-west, web2.eu-west etc…
Any clue ?
You could use inventory_hostname ?
Sorry, that wouldn’t help you unless you restructured but you need to use the variable you have assigned (hostname). Then you could iterate through the group and pick out this out. You might need to name it something diferrent, worried that you might get a collision when using “hostname”.
OK I got it working with the hostname variable. it seems I had to put the “ec2_facts:” run by a task in the beginning of the playbook.
Now I have two minor issues :
the first time we run the playbook the haproxy configuration has the default amazon ec2 hostnames . (the proxy playbook is executed at the end after the web servers)
the second time we run the same playbook we can see in haproxy configuration the name we defined using the hostname variable but it has only the short version web1 instead of web1.us-east.production … when you ssh to web1 you can see the full hostname and not the short.
Regards,
Nicolas.
More playbook output might help here. It sounds like an ordering issue or some variable collision or something but can’t really tell without seeing more.