From 32e44dc7bc8b977049ca887237c136b3ca98d757 Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Tue, 23 Jan 2018 10:55:58 +0000 Subject: [PATCH] templates: hostfile-setup: Improve regexp for host entries A hosts line may contain tabs instead of spaces and the '\ .*' regexp doesn't match on that case. As such, we can improve the regexp to simply look for any character after matching the address word. This fixes the following problem when an entry with a tab exists in the file ~$ cat -Et /etc/hosts|head -n1 127.0.0.1^Ilocalhost$ The entry is not updated by the script leading to the following problem fatal: [localhost]: FAILED! => { "assertion": "'127.0.1.1 localhost.openstack.local localhost' in hosts_content", "changed": false, "evaluated_to": false } Change-Id: I23d22cbf4317a3c9228bcdb6b3e9e6c2238fcfb7 --- templates/openstack-host-hostfile-setup.sh.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/openstack-host-hostfile-setup.sh.j2 b/templates/openstack-host-hostfile-setup.sh.j2 index cc194dec..0724b993 100644 --- a/templates/openstack-host-hostfile-setup.sh.j2 +++ b/templates/openstack-host-hostfile-setup.sh.j2 @@ -10,7 +10,7 @@ function insert_host_entry { sed -i "/^${ADDR}\b/d" /etc/hosts echo "${ENTRY}" | tee -a /etc/hosts elif grep -q "^${ADDR}\b" /etc/hosts; then - sed -i "s|^${ADDR}\b\ .*|${ENTRY}|" /etc/hosts + sed -i "s|^${ADDR}\b.*|${ENTRY}|" /etc/hosts elif ! grep -q "^${ENTRY}$" /etc/hosts; then echo "${ENTRY}" | tee -a /etc/hosts fi