Adjusts the /etc/hosts files to make all instances visible by the hostname in the subnet

This commit is contained in:
Victor Schröder
2016-04-02 23:28:12 +02:00
parent 3f2ce588c5
commit 7d40b5debb

View File

@@ -1,6 +1,8 @@
---
- hosts: nodes
sudo: true
vars_files:
- vagrant.yml
tasks:
- name: installing dependencies
@@ -80,3 +82,29 @@
line: "alias docker-compose='/opt/docker-compose/bin/docker-compose'"
state: present
regexp: '^alias docker-compose=.*$'
- name: building the /etc/hosts file with all nodes
lineinfile:
dest: /etc/hosts
line: "{{ item.private_ip }} {{ item.hostname }}"
regexp: "^{{ item.private_ip }} {{ item.hostname }}$"
state: present
with_items: instances
- name: fixing the hostname
hostname:
name: "{{ inventory_hostname }}"
- name: adjusting the /etc/hosts to the new hostname
lineinfile:
dest: /etc/hosts
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
owner: root
group: root
mode: 0644
with_items:
- regexp: '^127\.0\.0\.1'
line: "127.0.0.1 localhost {{ inventory_hostname }}"
- regexp: '^127\.0\.1\.1'
line: "127.0.1.1 {{ inventory_hostname }}"