File: inherit_from.cf

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (55 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# This example illustrates the use of inherit_from to inherit body attribute
# values from another body.
###############################################################################
#+begin_src cfengine3
bundle agent __main__
{
  files:
      "$(this.promise_filename).txt"
        content => "Hello World$(const.n)2$(const.n)3$(const.n)4$(const.n)half-way
6$(const.n)7$(const.n)8$(const.n)9$(const.n)Byeeeeeee",
        create => "true";

  reports:
      "The first 3 lines of this file are:"
        printfile => head_n( "$(this.promise_filename).txt", "3" );

      "The whole file contains:"
        printfile => cat( "$(this.promise_filename).txt" );
}

body printfile head_n(file, lines)
{
      # Sets file_to_print the same as cat
        inherit_from => cat( $(file) );

      # Overrides number_of_lines from cat
        number_of_lines => "$(lines)";
}
body printfile cat(file)
{
        file_to_print   => "$(file)";
        number_of_lines => "inf";
}
###############################################################################
#+begin_src example_output
#@ ```
#@ R: The first 3 lines of this file are:
#@ R: Hello World
#@ R: 2
#@ R: 3
#@ R: The whole file contains:
#@ R: Hello World
#@ R: 2
#@ R: 3
#@ R: 4
#@ R: half-way
#@ R: 6
#@ R: 7
#@ R: 8
#@ R: 9
#@ R: Byeeeeeee
#@ ```
#+end_src