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
23########################################################
24#
25# Copy and edit convergently
26#
27########################################################
28
29body common control
30
31{
32      bundlesequence  => { "example" };
33      version => "1.2.3";
34}
35
36########################################################
37
38bundle agent example
39
40{
41  vars:
42
43      "source" string => "/tmp";
44      "dest"   string => "/tmp";
45
46  files:
47
48      "/$(dest)/staging-file"
49
50      comment  => "Copy from source to buffer",
51      copy_from    => cp("$(source)/source-template"),
52      classes      => satisfied("copy_ok");
53
54    copy_ok::
55
56      "/$(dest)/final-file"
57
58      comment => "Build a file template and expand keys",
59      edit_line => myedits("/$(dest)/staging-file"),
60      edit_defaults => empty;
61
62}
63
64#########################################################
65
66body copy_from cp(from)
67
68{
69      source      => "$(from)";
70      compare     => "mtime";
71      type_check  => "true";
72}
73
74########################################################
75
76bundle edit_line myedits(f)
77
78{
79  insert_lines:
80
81      "$(f)"
82
83      comment     => "Populate empty file",
84      insert_type => "file";
85
86  replace_patterns:
87
88      "TEMPLATE_HOST_KEY"
89
90      comment => "Replace a place-marker with the name of this host",
91      replace_with => rp("$(sys.host)");
92
93}
94
95########################################################
96
97body replace_with rp(x)
98
99{
100      replace_value => "$(x)";
101      occurrences => "all";
102}
103
104#########################################################
105
106body classes satisfied(x)
107{
108      promise_repaired => { "$(x)" };
109      persist_time => "0";
110}
111
112#######################################################
113
114body edit_defaults empty
115
116{
117      empty_file_before_editing => "true";
118}
119