Merge branch 'hosts-aliases' into 'master'

__hosts: add --alias parameter

See merge request ungleich-public/cdist!901
This commit is contained in:
poljakowski 2020-06-30 22:52:52 +02:00
commit c5a8004c9a
3 changed files with 35 additions and 17 deletions

View file

@ -25,6 +25,10 @@ ip
state is ``present``, this parameter is mandatory, if state is state is ``present``, this parameter is mandatory, if state is
``absent``, this parameter is silently ignored. ``absent``, this parameter is silently ignored.
alias
An alias for the hostname.
This parameter can be specified multiple times (once per alias).
EXAMPLES EXAMPLES
-------- --------
@ -36,6 +40,8 @@ EXAMPLES
# previously configured via __hosts. # previously configured via __hosts.
__hosts happy --state absent __hosts happy --state absent
__hosts srv1.example.com --ip 192.168.0.42 --alias srv1
SEE ALSO SEE ALSO
-------- --------
@ -43,13 +49,14 @@ SEE ALSO
AUTHORS AUTHORS
------- -------
| Dmitry Bogatov <KAction@gnu.org>
Dmitry Bogatov <KAction@gnu.org> | Dennis Camera <dennis.camera--@--ssrq-sds-fds.ch>
COPYING COPYING
------- -------
Copyright (C) 2015,2016 Dmitry Bogatov. Free use of this software is granted Copyright \(C) 2015-2016 Dmitry Bogatov, 2019 Dennis Camera.
under the terms of the GNU General Public License version 3 or later You can redistribute it and/or modify it under the terms of the GNU General
(GPLv3+). Public License as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

View file

@ -1,29 +1,39 @@
#!/bin/sh -e #!/bin/sh -e
# Copyright (C) 2015 Bogatov Dmitry <KAction@gnu.org>
# #
# This program is free software: you can redistribute it and/or modify # Copyright (C) 2015 Bogatov Dmitry <KAction@gnu.org>
# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# 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 -ue #
hostname="$__object_id" set -e -u
state="$(cat "$__object/parameter/state")"
hostname=$__object_id
state=$(cat "$__object/parameter/state")
marker="# __hosts/$hostname" marker="# __hosts/$hostname"
set -- "__hosts/$hostname" --file /etc/hosts --state "$state" if [ "$state" = 'absent' ]
then
if [ "$state" = absent ] ; then set -- --regex "$marker"
__line "$@" --regex "$marker"
else else
ip="$(cat "$__object/parameter/ip")" ip=$(cat "$__object/parameter/ip")
__line "$@" --line "$ip $hostname $marker" 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" "$@"

View file

@ -0,0 +1 @@
alias