diff --git a/cdist/conf/type/__hosts/man.rst b/cdist/conf/type/__hosts/man.rst new file mode 100644 index 00000000..20f463e7 --- /dev/null +++ b/cdist/conf/type/__hosts/man.rst @@ -0,0 +1,57 @@ +cdist-type__hosts(7) +==================== + +NAME +---- + +cdist-type__hosts - manage entries in /etc/hosts + +DESCRIPTION +----------- + +Add or remove entries from */etc/hosts* file. + +OPTIONAL PARAMETERS +------------------- + +state + + If state is ``present``, make *object_id* resolve to *ip*. If + state is ``absent``, *object_id* will no longer resolve via + */etc/hosts*, if it was previously configured with this type. + Manually inserted entries are unaffected. + +ip + + IP address, to which hostname (=\ *object_id*) must resolve. If + state is ``present``, this parameter is mandatory, if state is + ``absent``, this parameter is silently ignored. + +EXAMPLES +-------- + +.. code-block:: sh + + # Now `funny' resolves to 192.168.1.76, + __hosts funny --ip 192.168.1.76 + # and `happy' no longer resolve via /etc/hosts if it was + # previously configured via __hosts. + __hosts happy --state absent + +SEE ALSO +-------- + +:strong:`hosts`\ (5) + +AUTHORS +------- + +Dmitry Bogatov + + +COPYING +------- + +Copyright (C) 2015,2016 Dmitry Bogatov. Free use of this software is granted +under the terms of the GNU General Public License version 3 or later +(GPLv3+). diff --git a/cdist/conf/type/__hosts/manifest b/cdist/conf/type/__hosts/manifest new file mode 100755 index 00000000..6fa21608 --- /dev/null +++ b/cdist/conf/type/__hosts/manifest @@ -0,0 +1,29 @@ +#!/bin/sh +# Copyright (C) 2015 Bogatov Dmitry +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +set -ue + +hostname="$__object_id" +state="$(cat "$__object/parameter/state")" +marker="# __hosts/$hostname" + +set -- "__hosts/$hostname" --file /etc/hosts --state "$state" + +if [ "$state" = absent ] ; then + __line "$@" --regex "$marker" +else + ip="$(cat "$__object/parameter/ip")" + __line "$@" --line "$ip $hostname $marker" +fi diff --git a/cdist/conf/type/__hosts/parameter/default/state b/cdist/conf/type/__hosts/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__hosts/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__hosts/parameter/optional b/cdist/conf/type/__hosts/parameter/optional new file mode 100644 index 00000000..411fc5d2 --- /dev/null +++ b/cdist/conf/type/__hosts/parameter/optional @@ -0,0 +1,2 @@ +state +ip diff --git a/docs/changelog b/docs/changelog index 6b869256..44631046 100644 --- a/docs/changelog +++ b/docs/changelog @@ -8,6 +8,7 @@ next: * Type __cron: Fix filter for new cron on sles12 sp2 (Daniel Heule) * Type __docker: Support absent state (Dominique Roux) * Type __docker_compose: Support absent state (Dominique Roux) + * New type: __hosts (Dmitry Bogatov) 4.4.1: 2016-12-17 * Documentation: Update docs for types that used man.rst as symbolic links (Darko Poljak)