Merge pull request #465 from darko-poljak/cdist-type__hosts

New type __hosts
This commit is contained in:
Darko Poljak 2017-02-02 19:51:42 +01:00 committed by GitHub
commit 037468fa9b
5 changed files with 90 additions and 0 deletions

View file

@ -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 <KAction@gnu.org>
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+).

View file

@ -0,0 +1,29 @@
#!/bin/sh
# Copyright (C) 2015 Bogatov Dmitry <KAction@gnu.org>
#
# 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 <http://www.gnu.org/licenses/>.
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

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,2 @@
state
ip

View file

@ -7,6 +7,7 @@ next:
* Type __cron: Fix filter for new cron on sles12 sp2 (Daniel Heule) * Type __cron: Fix filter for new cron on sles12 sp2 (Daniel Heule)
* Type __docker: Support absent state (Dominique Roux) * Type __docker: Support absent state (Dominique Roux)
* Type __docker_compose: Support absent state (Dominique Roux) * Type __docker_compose: Support absent state (Dominique Roux)
* New type: __hosts (Dmitry Bogatov)
4.4.1: 2016-12-17 4.4.1: 2016-12-17
* Documentation: Update docs for types that used man.rst as symbolic links (Darko Poljak) * Documentation: Update docs for types that used man.rst as symbolic links (Darko Poljak)