In the previous articles we created our infrastructure on AWS and configured the services. All using Ansible and creating an infrastructure as code.
When the number of servers or services grows, keeping track of their names clearly can be complicated.
This article describes how to manage your servers automatically using AWS Route53.
We’ve chosen to give names to our servers by creating a third level domain. For example: example.madisoft.it.
Each server has a public and private name based on the IP assigned to it.
- Public (IP) DNS
- nuvola-prod-backend-3.example.madisoft.it
- nuvola-prod-database-24.example.madisoft.it
- nuvola-dev-database-34.example.madisoft.it
- nuvola-issue8978-database-34.example.madisoft.it
- Private (IP 10.0.0.0/24) DNS
- local-prod-backend-0.example.madisoft.it
- local-prod-cache-sessioni-0.example.madisoft.it
- local-dev-database-14.example.madisoft.it
- local-issue8978-backend-0.example.madisoft.it
Within the playbook for creating the instance, we write a task that store its name on Route53. Below is the task for the public ip:
1 2 3 4 5 6 7 8 9 10 11 12 |
infrastructure_nuvola_ec2.yml - name: INFRASTRUCTURE NUVOLA EC2 | Assign backend dns route53: command: create zone: "{{ domain_tld }}" record: "nuvola-{{ nuvola_env }}-backend-{{ item.0 }}.{{ domain_tld }}" type: A value: '{{ item.1.public_ip }}' overwrite: yes ttl: "{{ ttl_expire }}" with_indexed_items: '{{ ec2_backend.instances }}' |
And here is for the private ip:
1 2 3 4 5 6 7 8 9 |
- name: INFRASTRUCTURE NUVOLA EC2 | Assign backend local dns route53: command: create zone: "{{ domain_tld }}" record: "local-{{ nuvola_env }}-backend-{{ item.0 }}.{{ domain_tld }}" type: A value: '{{ item.1.private_ip }}' overwrite: yes with_indexed_items: '{{ ec2_backend.instances }}' |
Now our servers are reachable with an easy-to-remember and easy-to-understand DNS name.
In the next article we’ll see how we migrated our content to the new provider.