-
Notifications
You must be signed in to change notification settings - Fork 12
/
tom.cf
136 lines (119 loc) · 3.42 KB
/
tom.cf
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
133
134
135
136
# Policy to update and run the Tom GitHub bot
# Note: This is example policy, for production changes, go to private infra repo
body file control
{
inputs => { "$(sys.local_libdir)/stdlib.cf", "$(sys.local_libdir)/vcs.cf" };
}
body contain in_tom
{
useshell => "useshell";
exec_owner => "tom";
chdir => "$(tom_update.tom_dir)";
}
bundle agent tom_init
{
files:
"/home/tom/."
create => "true",
depth_search => recurse_with_base("inf"),
file_select => all,
perms => mog("600", "tom", "users");
users:
"tom"
policy => "present",
description => "Tom",
home_dir => "/home/tom/",
group_primary => "users",
shell => "/bin/bash";
}
bundle agent tom_repo_init
{
vars:
"tom_dir" string => "/home/tom/self";
"remote_args" string => "add origin https://github.com/cfengine/cf-bottom.git";
files:
"/home/tom/self/."
create => "true",
depth_search => recurse("inf"),
file_select => all,
perms => mog("600", "tom", "users");
methods:
"Init"
usebundle => git_init($(tom_dir));
"Remote"
usebundle => git($(tom_dir), "remote", "$(remote_args)");
}
bundle agent tom_update
{
vars:
"tom_dir" string => "/home/tom/self";
classes:
"tom_exists" expression => isdir("$(tom_dir)");
methods:
!tom_exists::
"Init"
usebundle => tom_repo_init;
commands:
tom_exists::
"git pull origin master"
contain => in_tom;
"cp /home/tom/self/config.json /home/tom/config.json"
contain => in_tom;
}
bundle agent tom_install
{
commands:
"pip3 install --user -r requirements.txt"
contain => in_tom;
}
bundle agent tom_run
{
vars:
"secrets" string => "/home/tom/cfengine-secrets.json";
files:
# We promise to create the file if it does not exist as warn only so that we will surface a promise not kept in Mission Portal.
"$(secrets)"
action => policy( "warn" ),
handle => "cf-bottom_secrets_exist",
create => "true",
classes => results( "bundle", "cf_bottom_secrets" );
commands:
cf_bottom_secrets_kept.!cf_bottom_secrets_notkept::
"python3 -m tom --directory /home/tom/ --log-level info"
contain => in_tom,
depends_on => { "cf-bottom_secrets_exist" };
reports:
cf_bottom_secrets_notkept::
"WARNING: Missing secrets ($(secrets)), skipping cf-bottom run.";
}
bundle agent tom_main
{
meta:
"tags"
slist => {"autorun"},
if => filesexist( @(config_files) );
vars:
"config_files" slist => {"/home/tom/config.json",
"/home/tom/TOM_ENABLE"};
classes:
"has_tom_config" expression => filesexist(@(config_files));
methods:
has_tom_config::
"Init"
usebundle => "tom_init";
"Update"
usebundle => "tom_update";
"Install"
usebundle => "tom_install";
"Run"
usebundle => "tom_run";
reports:
inform_mode.!has_tom_config::
"Skipping execution, config.json or TOM_ENABLE missing in /home/tom";
}
bundle agent __main__
{
methods:
"Run"
usebundle => "tom_main";
}