diff --git a/ansible/roles/common/tasks/main.yaml b/ansible/roles/common/tasks/main.yaml index 02d1738..e33b369 100644 --- a/ansible/roles/common/tasks/main.yaml +++ b/ansible/roles/common/tasks/main.yaml @@ -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