forked from ungleich-public/cdist
[type/__hosts] Fix when used without --alias
This commit is contained in:
parent
b8752e9ee3
commit
a5ae26116b
1 changed files with 13 additions and 10 deletions
|
@ -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
|
||||||
|
ip=$(cat "${__object}/parameter/ip")
|
||||||
|
if test -s "${__object}/parameter/alias"
|
||||||
then
|
then
|
||||||
set -- --regex "$marker"
|
|
||||||
else
|
|
||||||
ip=$(cat "$__object/parameter/ip")
|
|
||||||
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")
|
||||||
|
|
||||||
set -- --line "$(printf '%s\t%s%s %s' \
|
|
||||||
"$ip" "$hostname" "$aliases" "$marker")"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
__line "__hosts/$hostname" --file /etc/hosts --state "$state" "$@"
|
set -- --line "$(printf '%s\t%s%s %s' \
|
||||||
|
"${ip}" "${hostname}" "${aliases}" "${marker}")"
|
||||||
|
else
|
||||||
|
set -- --regex "$(echo "${marker}" | sed -e 's/\./\\./')$"
|
||||||
|
fi
|
||||||
|
|
||||||
|
__line "/etc/hosts:${hostname}" --file /etc/hosts --state "${state}" "$@"
|
||||||
|
|
Loading…
Reference in a new issue