1# Copyright 2021 Northern.tech AS 2 3# This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 4 5# This program is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License as published by the 7# Free Software Foundation; version 3. 8 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13 14# You should have received a copy of the GNU General Public License 15# along with this program; if not, write to the Free Software 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 17 18# To the extent this program is licensed as part of the Enterprise 19# versions of Cfengine, the applicable Commercial Open Source License 20# (COSL) may apply to this file if you as a licensee so wish it. See 21# included file COSL.txt. 22#+begin_src prep 23#@ ``` 24#@ echo alpha > /tmp/cfe_hostlist 25#@ echo beta >> /tmp/cfe_hostlist 26#@ echo gamma >> /tmp/cfe_hostlist 27#@ echo "Set HOSTNAME appropriately beforehand" 28#@ echo "$(hostname -f)" | tr 'A-Z' 'a-z' >> /tmp/cfe_hostlist 29#@ echo "Delta Delta Delta may I help ya help ya help ya" 30#@ echo delta1 >> /tmp/cfe_hostlist 31#@ echo delta2 >> /tmp/cfe_hostlist 32#@ echo delta3 >> /tmp/cfe_hostlist 33#@ echo may1.I.help.ya >> /tmp/cfe_hostlist 34#@ echo may2.I.help.ya >> /tmp/cfe_hostlist 35#@ echo may3.I.help.ya >> /tmp/cfe_hostlist 36#@ ``` 37#+end_src 38############################################################################### 39#+begin_src cfengine3 40body common control 41{ 42 bundlesequence => { "peers" }; 43} 44 45bundle agent peers 46{ 47 vars: 48 49 "mygroup" slist => peers("/tmp/cfe_hostlist","#.*",4); 50 51 "myleader" string => peerleader("/tmp/cfe_hostlist","#.*",4); 52 53 "all_leaders" slist => peerleaders("/tmp/cfe_hostlist","#.*",4); 54 55 reports: 56 57 # note that the current host name is fourth in the host list, so 58 # its peer group is the first 4-host group, minus the host itself. 59 "/tmp/cfe_hostlist mypeer $(mygroup)"; 60 # note that the current host name is fourth in the host list, so 61 # the peer leader is "alpha" 62 "/tmp/cfe_hostlist myleader $(myleader)"; 63 "/tmp/cfe_hostlist another leader $(all_leaders)"; 64 "Unable to find my fully qualified hostname $(sys.fqhost) in /tmp/cfe_hostlist. Can't determine peers." 65 if => not( regline( $(sys.fqhost), "/tmp/cfe_hostlist" ) ); 66} 67#+end_src 68############################################################################### 69#+begin_src example_output 70#@ ``` 71#@ R: /tmp/cfe_hostlist mypeer alpha 72#@ R: /tmp/cfe_hostlist mypeer beta 73#@ R: /tmp/cfe_hostlist mypeer gamma 74#@ R: /tmp/cfe_hostlist myleader alpha 75#@ R: /tmp/cfe_hostlist another leader alpha 76#@ R: /tmp/cfe_hostlist another leader delta1 77#@ R: /tmp/cfe_hostlist another leader may2.I.help.ya 78#@ ``` 79#+end_src 80