Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions ansible/roles/common/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
---

####################
# Set hostname
####################

# Set hostname to internal DNS FQN. Default name is not fully qualified.
# As nodes register themselves using hostname, if not FQN other nodes will not be able to resolve it.
# As nodes register themselves using hostname, if not FQN other nodes will not be able to resolve it.

- name: Get the internal DNS name of the host
shell: 'curl -sSL http://169.254.169.254/latest/meta-data/local-hostname'
register: ec2_private_dns_name

- name: Add internal DNS name to hosts file
lineinfile:
dest: /etc/hosts
regexp: '^127\.0\.0\.1'
line: '127.0.0.1 localhost {{ ec2_private_dns_name }}'
line: '127.0.0.1 localhost {{ ec2_private_dns_name.stdout }}'
owner: root
group: root
mode: 0644
become: true

- debug: var=ec2_private_dns_name

- name: Set internal DNS name as hostname
shell: "hostname {{ ec2_private_dns_name }}"
shell: "hostname {{ ec2_private_dns_name.stdout }}"
become: true