Created
May 5, 2012 20:35
-
-
Save zzamboni/2605453 to your computer and use it in GitHub Desktop.
Code examples from CFEngine Tip #002: How to pass arguments to bundles using arrays: http://blog.cf-learn.info/cfengine-tip-002-how-to-pass-arguments-to-bun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bundle agent configfiles | |
| { | |
| vars: | |
| # SSHD configuration to set | |
| "sshd[Protocol]" string => "2"; | |
| "sshd[X11Forwarding]" string => "yes"; | |
| "sshd[UseDNS]" string => "no"; | |
| methods: | |
| "sshd" usebundle => edit_sshd("configfiles.sshd"); | |
| } | |
| bundle agent edit_sshd | |
| { | |
| files: | |
| "/etc/sshd/sshd_config" | |
| handle => "edit_sshd", | |
| comment => "Set desired sshd_config parameters", | |
| edit_line => set_config_values("configfiles.sshd"), | |
| classes => if_repaired("restart_sshd"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bundle edit_line set_config_values(v) | |
| { | |
| vars: | |
| "index" slist => getindices("$(v)"); | |
| "cindex[$(index)]" string => canonify("$(index)"); | |
| replace_patterns: | |
| # If the line is there, maybe commented out, uncomment and replace with | |
| # the correct value | |
| "^\s*($(index)\s+(?!$($(v)[$(index)])).*|# ?$(index)\s+.*)$" | |
| replace_with => value("$(index) $($(v)[$(index)])"), | |
| classes => always("replace_attempted_$(cindex[$(index)])"); | |
| insert_lines: | |
| "$(index) $($(v)[$(index)])" | |
| ifvarclass => "replace_attempted_$(cindex[$(index)])"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bundle agent create_users(info) | |
| { | |
| vars: | |
| "user" slist => getindices("$(info)"); | |
| classes: | |
| "add_$(user)" not => userexists("$(user)"); | |
| commands: | |
| linux:: | |
| "/usr/sbin/useradd $($(info)[$(user)][flags]) -u $($(info)[$(user)][uid]) | |
| -g $($(info)[$(user)][gid]) -d $($(info)[$(user)][home]) | |
| -s $($(info)[$(user)][shell]) -c '$($(info)[$(user)][fullname])' $(user)" | |
| ifvarclass => "add_$(user)"; | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bundle agent manage_users | |
| { | |
| vars: | |
| # Users to create | |
| "users[root][fullname]" string => "System administrator"; | |
| "users[root][uid]" string => "0"; | |
| "users[root][gid]" string => "0"; | |
| "users[root][home]" string => "/root"; | |
| "users[root][shell]" string => "/bin/bash"; | |
| "users[root][flags]" string => "-o -m"; | |
| "users[root][password]" string => "FkDMzhB1WnOp2"; | |
| "users[zamboni][fullname]" string => "Diego Zamboni"; | |
| "users[zamboni][uid]" string => "501"; | |
| "users[zamboni][gid]" string => "users"; | |
| "users[zamboni][home]" string => "/home/zamboni"; | |
| "users[zamboni][shell]" string => "/bin/bash"; | |
| "users[zamboni][flags]" string => "-m"; | |
| "users[zamboni][password]" string => "dk52ia209rfuh"; | |
| methods: | |
| "users" usebundle => create_users("manage_users.users"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment