Ansibly fix_etc_hosts

Replace fix_etc_hosts bash function for fix_etc_hosts role

Change-Id: Icfabbfeec649b43328b5251c5b9e481f1f58b002
This commit is contained in:
Ricardo Carrillo Cruz 2016-11-24 11:22:10 +00:00
parent dd4eb2c5f3
commit 33a3266914
3 changed files with 12 additions and 15 deletions

View File

@ -339,18 +339,6 @@ function git_clone_and_cd {
cd $short_project
}
function fix_etc_hosts {
# HPcloud stopped adding the hostname to /etc/hosts with their
# precise images.
HOSTNAME=`/bin/hostname`
if ! grep $HOSTNAME /etc/hosts >/dev/null; then
echo "Need to add hostname to /etc/hosts"
sudo bash -c 'echo "127.0.1.1 $HOSTNAME" >>/etc/hosts'
fi
}
function fix_disk_layout {
# Don't attempt to fix disk layout more than once
[[ -e /etc/fixed_disk_layout ]] && return 0 || sudo touch /etc/fixed_disk_layout
@ -596,9 +584,6 @@ function setup_host {
local xtrace=$(set +o | grep xtrace)
set -o xtrace
# This is necessary to keep sudo from complaining
fix_etc_hosts
# We set some home directories under $BASE, make sure it exists.
sudo mkdir -p $BASE

View File

@ -0,0 +1,11 @@
---
- name: Check whether /etc/hosts contains hostname
command: grep {{ ansible_hostname }} /etc/hosts
changed_when: False
failed_when: False
register: grep_out
- name: Add hostname to /etc/hosts
lineinfile: dest=/etc/hosts insertafter=EOF line='127.0.1.1 {{ ansible_hostname }}'
become: yes
when: grep_out.rc != 0

View File

@ -5,3 +5,4 @@
- devstack_gate_vars.yaml
roles:
- gather_host_info
- fix_etc_hosts