Guest User

CF3 Client/Server Working Config

a guest
Aug 4th, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.74 KB | None | 0 0
  1. #failsafe.cf
  2. bundle common g
  3. {
  4. vars:
  5. "masterfiles" string => "/var/cfengine/masterfiles";
  6. "phost" string => "17.17.0.28"; # Do NOT use DNS here in case we break DNS resolution.
  7. }
  8.  
  9. body common control
  10. {
  11. bundlesequence => { "update" };
  12. inputs => { "update.cf" };
  13. }
  14.  
  15.  
  16.  
  17. # site.cf
  18. bundle common g
  19. {
  20. vars:
  21. "masterfiles" string => "/var/cfengine/masterfiles";
  22. "phost" string => "cf0.xxx.xxx";
  23.  
  24. SuSE::
  25. "crontab" string => "/var/spool/cron/tabs/root";
  26.  
  27. !SuSE::
  28. "crontab" string => "/var/spool/cron/crontabs/root";
  29. }
  30.  
  31. bundle agent main
  32. {
  33. vars:
  34. "blacklisted_packages"
  35. slist => {
  36. "NetworkManager"
  37. };
  38.  
  39. "standard_packages"
  40. slist => {
  41. "bind-utils",
  42. "check_mk-agent",
  43. "check_mk-agent-logwatch",
  44. "man",
  45. "mlocate",
  46. "mtr",
  47. "nano",
  48. "ntp",
  49. "openssh-clients",
  50. "rsync",
  51. "tcpdump",
  52. "telnet",
  53. "traceroute",
  54. "wget"
  55. };
  56.  
  57. cfserver::
  58. "cfserver_processes" slist => { "cf-monitord", "cf-serverd" };
  59.  
  60. classes:
  61. "cfserver" expression => strcmp("$(sys.fqhost)","cf0.xxx.xxx");
  62.  
  63. commands:
  64. cfserver::
  65. "$(sys.workdir)/bin/$(cfserver_processes)"
  66. ifvarclass => canonify("start_$(cfserver_processes)");
  67.  
  68. files:
  69. # Cleanup tmp
  70. "/tmp"
  71. delete => tidy,
  72. file_select => days_old("7"),
  73. depth_search => recurse("inf");
  74.  
  75. # Copy /etc/motd
  76. "/etc/motd"
  77. perms => usystem("0644"),
  78. copy_from => umycopy("$(g.masterfiles)/etc/motd");
  79.  
  80. # Copy /etc/resolv.conf
  81. "/etc/resolv.conf"
  82. perms => usystem("0644"),
  83. copy_from => umycopy("$(g.masterfiles)/etc/resolv.conf");
  84.  
  85. # Copy /etc/sysconfig/autofsck
  86. "/etc/sysconfig/autofsck"
  87. perms => usystem("0644"),
  88. copy_from => umycopy("$(g.masterfiles)/etc/sysconfig/autofsck");
  89.  
  90. # Copy /etc/xinetd.d/check_mk
  91. "/etc/xinetd.d/check_mk"
  92. perms => usystem("0644"),
  93. copy_from => umycopy("$(g.masterfiles)/etc/xinetd.d/check_mk");
  94.  
  95. # Copy SSH Keys
  96. "/root/.ssh/."
  97. create => "true",
  98. perms => usystem("0700");
  99. "/root/.ssh/authorized_keys"
  100. create => "true",
  101. perms => usystem("0600"),
  102. edit_line => authorized_keys;
  103.  
  104. # Edit /etc/sysconfig/network
  105. "/etc/sysconfig/network"
  106. perms => usystem("0644"),
  107. edit_line => etc_sysconfig_network;
  108.  
  109. # Uncomment this to perform a change-detection scan
  110. # "/usr"
  111. # changes => lay_trip_wire,
  112. # depth_search => recurse("inf"),
  113. # action => measure;
  114.  
  115. methods:
  116. "yum_config"
  117. usebundle => "yum_config";
  118.  
  119. "manage_users"
  120. usebundle => "manage_users";
  121.  
  122. "sshd_config"
  123. usebundle => "sshd_config";
  124.  
  125. "vmware_tools"
  126. usebundle => "vmware_tools";
  127.  
  128. packages:
  129. "$(standard_packages)"
  130. package_method => generic,
  131. package_policy => "add";
  132.  
  133. "$(blacklisted_packages)"
  134. package_method => generic,
  135. package_policy => "delete";
  136.  
  137. processes:
  138. cfserver::
  139. "$(cfserver_processes)"
  140. restart_class => canonify("start_$(cfserver_processes)");
  141. }
  142.  
  143. body action measure
  144. {
  145. measurement_class => "Detect Changes in /usr";
  146. ifelapsed => "240"; # 4 hours
  147. expireafter => "240"; # 4 hours
  148. }
  149.  
  150. bundle agent garbage_collection
  151. {
  152. files:
  153. # Cleanup outputs
  154. "$(sys.workdir)/outputs"
  155. delete => tidy,
  156. file_select => days_old("3"),
  157. depth_search => recurse("inf");
  158. }
  159.  
  160. bundle agent manage_users
  161. {
  162. vars:
  163. "group[ryan]" string => "ryan::500:";
  164. "group[root]" string => "root:x:0:root";
  165.  
  166. "shadow[ryan]" string => "ryan:$1$AAAAAAAAAAAAAAAAAAAAAAAACLQL3FO0:15183::::::";
  167. "shadow[root]" string => "root:$1$BBBBBBBBBBBBBBBBBBBBBBBB1IX7tZW.:15183::::::";
  168.  
  169. "user[ryan]" string => "ryan:x:500:500::/home/ryan:/bin/bash";
  170. "user[root]" string => "root:x:0:0:root:/root:/bin/bash";
  171.  
  172. "users" slist => getindices("user");
  173.  
  174. files:
  175. # Add Users
  176. "/etc/passwd"
  177. edit_line => append_users_starting("manage_users.user");
  178.  
  179. # Add Groups
  180. "/etc/group"
  181. edit_line => append_groups_starting("manage_users.group");
  182.  
  183. # Set Passwords
  184. "/etc/shadow"
  185. edit_line => set_passwords("manage_users.shadow", "/etc/shadow");
  186.  
  187. # Create Home Directories
  188. "/home/$(users)/."
  189. create => "true",
  190. perms => mog("755", "$(users)", "$(users)");
  191. }
  192.  
  193. bundle agent sshd_config
  194. {
  195. vars:
  196. "sshd[ClientAliveInterval]" string => "1800";
  197. "sshd[ClientAliveCountMax]" string => "0";
  198. "sshd[IgnoreRhosts]" string => "yes";
  199. "sshd[HostbasedAuthentication]" string => "no";
  200. "sshd[PermitEmptyPasswords]" string => "no";
  201. "sshd[PermitRootLogin]" string => "without-password";
  202. "sshd[Protocol]" string => "2";
  203.  
  204. commands:
  205. restart_sshd::
  206. "/etc/init.d/sshd restart";
  207.  
  208. files:
  209. "/etc/ssh/sshd_config"
  210. classes => if_repaired("restart_sshd"),
  211. edit_line => set_keyword_values("sshd_config.sshd"),
  212. perms => usystem("0600");
  213.  
  214. packages:
  215. "openssh-server"
  216. package_method => generic,
  217. package_policy => "add";
  218.  
  219. processes:
  220. "/usr/sbin/sshd"
  221. restart_class => "restart_sshd";
  222. }
  223.  
  224. bundle agent vmware_tools
  225. {
  226. vars:
  227. "mac" string => execresult("/sbin/ifconfig eth0 | /bin/grep -E -o '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'", "useshell");
  228.  
  229. classes:
  230. "vm" expression => regcmp("^00:50:.*", "$(mac)");
  231.  
  232. packages:
  233. vm::
  234. "vmware-tools"
  235. package_method => generic,
  236. package_policy => "add";
  237.  
  238. # reports:
  239. # vm::
  240. # "This machine is a VM.";
  241. }
  242.  
  243. bundle agent yum_config
  244. {
  245. classes:
  246. "rhel5"
  247. expression => regline("^CentOS Linux release 5.*", "/etc/redhat-release");
  248.  
  249. "rhel6"
  250. expression => regline("^CentOS Linux release 6.*", "/etc/redhat-release");
  251.  
  252. files:
  253. rhel5::
  254. "/etc/yum.repos.d/cobbler-config.repo"
  255. perms => usystem("0644"),
  256. copy_from => umycopy("$(g.masterfiles)/etc/yum.repos.d/cobbler-config.repo.rhel5");
  257.  
  258. rhel6::
  259. "/etc/yum.repos.d/cobbler-config.repo"
  260. perms => usystem("0644"),
  261. copy_from => umycopy("$(g.masterfiles)/etc/yum.repos.d/cobbler-config.repo.rhel6");
  262. }
  263.  
  264. bundle edit_line authorized_keys
  265. {
  266. insert_lines:
  267. "ssh-rsa CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC== [email protected]";
  268. }
  269.  
  270. bundle edit_line etc_sysconfig_network
  271. {
  272. insert_lines:
  273. "NOZEROCONF=yes";
  274. "USERCTL=no";
  275. }
  276.  
  277. bundle edit_line set_keyword_values(v)
  278. {
  279. vars:
  280. "index" slist => getindices("$(v)");
  281.  
  282. # Be careful if the index string contains funny chars
  283. "cindex[$(index)]" string => canonify("$(index)");
  284.  
  285. field_edits:
  286. # match a line starting like "keyword value"
  287. "$(index)\s* .*"
  288. edit_field => col(" ", "2", "$($(v)[$(index)])", "set"),
  289. classes => if_ok("not_$(cindex[$(index)])");
  290.  
  291. insert_lines:
  292. "$(index) $($(v)[$(index)])"
  293. ifvarclass => "!not_$(cindex[$(index)])";
  294. }
  295.  
  296. bundle edit_line set_passwords(v,f)
  297. {
  298. vars:
  299. "index" slist => getindices("$(v)");
  300.  
  301. classes:
  302. "correct" expression => regline("^$($(v)[$(index)])", "$(f)");
  303.  
  304. delete_lines:
  305. !correct::
  306. "^$(index):.*";
  307.  
  308. insert_lines:
  309. "$($(v)[$(index)])";
  310. }
  311.  
  312. bundle server access_rules
  313. {
  314. access:
  315. "${g.masterfiles}"
  316. admit => {
  317. "0.0.0.0/0"
  318. };
  319. }
  320.  
  321.  
  322.  
  323. # promises.cf
  324. body common control {
  325. bundlesequence => {
  326. "update",
  327. "garbage_collection",
  328. "main"
  329. };
  330.  
  331. inputs => {
  332. "update.cf",
  333. "site.cf",
  334. "cfengine_stdlib.cf"
  335. };
  336. }
  337.  
  338. body executor control
  339. {
  340. exec_command => "$(sys.workdir)/bin/cf-agent -f failsafe.cf && $(sys.workdir)/bin/cf-agent";
  341. executorfacility => "LOG_DAEMON";
  342. mailmaxlines => "100";
  343. mailto => "[email protected]";
  344. smtpserver => "mail.xxx.xxx";
  345. splaytime => "1";
  346. }
  347.  
  348. body monitor control
  349. {
  350. forgetrate => "0.7";
  351. }
  352.  
  353. body reporter control
  354. {
  355. reports => { "performance", "last_seen", "monitor_history" };
  356. build_directory => "/tmp/nerves";
  357. report_output => "html";
  358. }
  359.  
  360. body runagent control
  361. {
  362. hosts => {
  363. "127.0.0.1"
  364. };
  365. }
  366.  
  367. body server control
  368. {
  369. allowconnects => { "0.0.0.0/0" };
  370. allowallconnects => { "0.0.0.0/0" };
  371. allowusers => { "root" };
  372. cfruncommand => "$(sys.workdir)/bin/cf-agent";
  373. logallconnections => "true";
  374. maxconnections => "10";
  375. skipverify => { "0.0.0.0/0" };
  376. trustkeysfrom => { "0.0.0.0/0" };
  377. }
  378.  
  379.  
  380.  
  381. # update.cf
  382. bundle agent update
  383. {
  384. vars:
  385. "inputs" string => "$(g.masterfiles)/var/cfengine/inputs";
  386.  
  387. files:
  388. # Alter permissions
  389. "/var/cfengine/."
  390. create => "true",
  391. perms => usystem("0700");
  392.  
  393. # Alter permissions
  394. "/var/cfengine/bin/."
  395. create => "true",
  396. perms => usystem("0700");
  397.  
  398. # Alter permissions
  399. "/var/cfengine/ppkeys/."
  400. create => "true",
  401. perms => usystem("0700");
  402.  
  403. # Copy /var/cfengine/inputs
  404. "/var/cfengine/inputs"
  405. copy_from => umycopy("$(inputs)"),
  406. depth_search => urecurse("inf"),
  407. file_select => cf_files,
  408. perms => usystem("0600");
  409. }
  410.  
  411. body copy_from umycopy(from)
  412. {
  413. source => "$(from)";
  414. servers => { "$(g.phost)" };
  415. compare => "digest";
  416. verify => "true";
  417. purge => "true";
  418. }
  419.  
  420. body depth_search urecurse(d)
  421. {
  422. depth => "$(d)";
  423. exclude_dirs => { "\.svn" };
  424. }
  425.  
  426. body file_select cf_files
  427. {
  428. leaf_name => { "\.cf$" };
  429. file_result => "leaf_name";
  430. }
  431.  
  432. body perms usystem(p)
  433. {
  434. groups => { "root" };
  435. mode => "$(p)";
  436. owners => { "root" };
  437. }
Advertisement
Add Comment
Please, Sign In to add comment