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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user