# Update EC2 instances hostnames to their EC2 instance tags

**URL:** <https://forum.ansible.com/t/update-ec2-instances-hostnames-to-their-ec2-instance-tags/33232>\
**Category:** Ansible Project\
**Created:** [June 22, 2020, 9:43pm UTC](https://forum.ansible.com/t/update-ec2-instances-hostnames-to-their-ec2-instance-tags/33232 "2020-06-22T21:43:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leo2](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@Leo2](https://forum.ansible.com/u/Leo2)\
**Post date:** [June 22, 2020, 9:43pm UTC](https://forum.ansible.com/t/update-ec2-instances-hostnames-to-their-ec2-instance-tags/33232/1 "2020-06-22T21:43:14Z")

</div>

Hi everyone,

I have got a question about the EC2 and it related modules. I would like to update the hostnames of all of the EC2 instances created by another role within the same playbook (all EC2 instances are dynamic inventories, no host file) by using their EC2 instance tag. For example, if an instance has a tag “Name: dbserver01”, I would like to update its hostname to “dbserver01.mydomain,mycompany.local”. What should I do?
