Created
November 25, 2010 05:26
-
-
Save zzamboni/714948 to your computer and use it in GitHub Desktop.
Cfengine bundle for editing sshd configuration file and restarting sshd if needed
This file contains 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
# Parameters are: | |
# file: file to edit | |
# params: an array indexed by parameter name, containing the corresponding values. For example: | |
# "sshd[Protocol]" string => "2"; | |
# "sshd[X11Forwarding]" string => "yes"; | |
# "sshd[UseDNS]" string => "no"; | |
# Diego Zamboni, November 2010 | |
bundle agent edit_sshd(file,params) | |
{ | |
files: | |
"$(file)" | |
handle => "edit_sshd", | |
comment => "Set desired sshd_config parameters", | |
edit_line => set_config_values("$(params)"), | |
classes => if_repaired("restart_sshd"); | |
commands: | |
restart_sshd.!no_restarts:: | |
"/etc/init.d/sshd restart" | |
handle => "sshd_restart", | |
comment => "Restart sshd if the configuration file was modified"; | |
} | |
bundle edit_line set_config_values(v) | |
# Sets the RHS of configuration items in the file of the form | |
# LHS RHS | |
# If the line is commented out with #, it gets uncommented first. | |
# Adds a new line if none exists. | |
# The argument is an associative array containing v[LHS]="rhs" | |
# Based on set_variable_values from cfengine_stdlib.cf, modified to | |
# use whitespace as separator, and to handle commented-out lines. | |
{ | |
vars: | |
"index" slist => getindices("$(v)"); | |
# Be careful if the index string contains funny chars | |
"cindex[$(index)]" string => canonify("$(index)"); | |
field_edits: | |
# If the line is there, but commented out, first uncomment it | |
"#+$(index)\s+.*" | |
edit_field => col("\s+","1","$(index)","set"); | |
# match a line starting like the key something | |
"$(index)\s+.*" | |
edit_field => col("\s+","2","$($(v)[$(index)])","set"), | |
classes => if_ok("not_$(cindex[$(index)])"); | |
insert_lines: | |
"$(index) $($(v)[$(index)])", | |
ifvarclass => "!not_$(cindex[$(index)])"; | |
} |
This file contains 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: | |
"sshdconfig" string => "/etc/ssh/sshd_config"; | |
# SSHD configuration to set | |
"sshd[Protocol]" string => "2"; | |
"sshd[X11Forwarding]" string => "yes"; | |
"sshd[UseDNS]" string => "no"; | |
methods: | |
"sshd" usebundle => edit_sshd("$(sshdconfig)", "configfiles.sshd"); | |
} |
Author
zzamboni
commented
Jun 20, 2012
via email
There are Cfengine modes for both Emacs and vi, but I don't know of any support for visual studio or Xcode.
…--Diego
On Jun 20, 2012, at 11:49 AM, ***@***.*** wrote:
Thanks. I'll give that a shot, and get back to you. It'd be really cool to see a way to get CFEngine code syntax coloring added to Visual Studio, or Xcode.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/714948
Interesting. It'd be great to get an Xcode or VS plugin working.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment