summaryrefslogtreecommitdiff
path: root/var/www/html/cfengine/update.cf
blob: 039636c8c28087f7d1f497c3ca6d12f6454b9629 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# update promises

bundle agent update
{
    vars:

        any::

            "master_server"   string => "phost1.eurospider.com";

            "master_location" string => "/var/cfengine/masterfiles";

            "ignore_list"     slist  => { "\.svn", ".*~" };

        redhat|freebsd::

            "inputs_location" string => "$(sys.workdir)/inputs/.";

        debian::

            "inputs_location" string => "/etc/cfengine3/.";

    files:

        any::

            "$(sys.workdir)/."

                create  => "true",
                perms   => u_p( "0700" ),
                action  => uimmediate;

        redhat|freebsd::

            "$(sys.workdir)/bin/."

                create  => "true",
                perms   => u_p( "0700" ),
                action  => uimmediate;

        debian::

            "$(sys.workdir)/bin/."

                link_from => u_ln_s( "/usr/sbin" ),
                action  => uimmediate;

        any::

            "$(sys.workdir)/ppkeys/."

                perms   => u_p( "0700" ),
                action  => uimmediate;

        redhat|freebsd::

            "$(sys.workdir)/bin"

                comment      => "copy binaries from RPM location",
                perms        => u_p( "700" ),
                copy_from    => mycopy( "/usr/local/sbin", "localhost" ),
                depth_search => recurse( "inf" ),
                action       => uimmediate;

        bunsen::

            "$(inputs_location)"

                comment      => "copy from local masterfiles on master policy server",
                perms        => u_p( "600" ),
                copy_from    => mycopy("$(master_location)","localhost"),
                depth_search => recurse_ignore( "inf", "$(ignore_list)" ),
                action       => uimmediate;

        !bunsen::

            "$(inputs_location)"

                comment      => "all others fetch the promises from the policy master (also the slave)",
                perms        => u_p( "600" ),
                copy_from    => remote_copy( "$(master_location)", "$(master_server)" ),
                depth_search => recurse_ignore( "inf", "$(ignore_list)" ),
                action       => uimmediate;

    commands:

        bunsen::

           "/bin/sh -c 'cd $(master_location) && svn up >/dev/null 2>&1'"

               comment => "update the master policy files from SVN";
}

# self-contained functions, must work even if libaries have bugs

# Set permissions
body perms u_p( p )
{
    mode => "$(p)";
}

# Basic copy function (for local file copies)
body copy_from mycopy( from, server )
{
    source      => "$(from)";
    compare     => "digest";
}

# Remote copy function, secure
body copy_from remote_copy( sourcedir, sourceserver )
{
    source      => "$(sourcedir)";   
    servers     => { "$(sourceserver)" };
    compare     => "digest";
    encrypt     => "true";
    verify      => "true";
    trustkey    => "true";
    preserve    => "true";
}

# Copy if at least 1 minute has elapsed
body action uimmediate
{
    ifelapsed => "1";
}

body link_from u_ln_s(x)
{
    link_type => "symlink";
    source => "$(x)";
    when_no_source => "force";
}