Merge branch 'fix/type/__hosts/no-alias' into 'master'

__hosts: Fix when used without --alias

See merge request ungleich-public/cdist!906
This commit is contained in:
poljakowski 2020-07-12 09:31:01 +02:00
commit c62eaa6eab

View file

@ -19,21 +19,24 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
set -e -u set -e
hostname=$__object_id hostname=$__object_id
state=$(cat "$__object/parameter/state") state=$(cat "${__object}/parameter/state")
marker="# __hosts/$hostname" marker="# __hosts/${hostname}"
if [ "$state" = 'absent' ] if test "${state}" != 'absent'
then then
set -- --regex "$marker" ip=$(cat "${__object}/parameter/ip")
else if test -s "${__object}/parameter/alias"
ip=$(cat "$__object/parameter/ip") then
aliases=$(while read -r a; do printf '\t%s' "$a"; done <"$__object/parameter/alias") aliases=$(while read -r a; do printf '\t%s' "$a"; done <"$__object/parameter/alias")
fi
set -- --line "$(printf '%s\t%s%s %s' \ set -- --line "$(printf '%s\t%s%s %s' \
"$ip" "$hostname" "$aliases" "$marker")" "${ip}" "${hostname}" "${aliases}" "${marker}")"
else
set -- --regex "$(echo "${marker}" | sed -e 's/\./\\./')$"
fi fi
__line "__hosts/$hostname" --file /etc/hosts --state "$state" "$@" __line "/etc/hosts:${hostname}" --file /etc/hosts --state "${state}" "$@"