Skip to content

Instantly share code, notes, and snippets.

View raphink's full-sized avatar
🐝
eBPF everything!

Raphaël Pinson raphink

🐝
eBPF everything!
View GitHub Profile
@raphink
raphink / gist:5853347
Created June 24, 2013 20:30
Augeas lens debug note
<lutter> hmm .. ok; I just put a 'let _ = (print_regexp (lens_ctype values) ); print_endline ""' in there
<lutter> and get
<lutter> /([^\n;]|[^\n ];|;[^\n ])*( ; ([^\n;]|[^\n ];|;[^\n ])*)*/
positionable do
def insync?(is)
# define sync
end
end
1.8.7-p371 :001 > target = '/files/etc/toto'
=> "/files/etc/toto"
1.8.7-p371 :002 > spath = '/files/etc/toto/truc/IfModule[3]/directive[6]'
=> "/files/etc/toto/truc/IfModule[3]/directive[6]"
1.8.7-p371 :003 > spath.slice(target.length+1..-1).sub(/(.*)\/directive(?:\[\d+\])?/, '\1')
=> "truc/IfModule[3]"
@raphink
raphink / augeas.rb
Last active December 19, 2015 22:39
lens { 'Shells.lns' }
resource_path { |r| "$target/*[.='#{r[:name]}']" }
# exists? is automatic
# destroy is automatic
def create
augopen! { |aug| aug.set('$target/01', resource[:name]) }
end
# Define a method using augopen
#
# @param [Symbol] meth the name of the method to create
# @yield [aug] block that uses the Augeas handle
# @yieldparam [Augeas] aug open Augeas handle
# @api public
def define_augmethod(meth, &block)
define_method(meth) do
instance_exec augopen, &block
end
$ rspec --color spec/unit/puppet/apache_setenv_spec.rb
....FF.
Failures:
1) Puppet::Type::Apache_setenv::ProviderAugeas with simple file when update existing should update existing
Failure/Error: ))
expected: []
got: [wrong number of arguments (2 for 0), change from test.com to test2.com failed: wrong number of arguments (2 for 0)] (using ==)
Diff:
#!/usr/bin/augtool -Asf
# Loaded with -A, add association now
set /augeas/load/Pg_Hba/lens Pg_Hba.lns
set /augeas/load/Pg_Hba/incl /etc/postgresql/9.1/main/pg_hba.conf
load
# Make sure file exists
defnode file /files/etc/postgresql/9.1/main/pg_hba.conf
augeas {
'Add line if missing':
context => '/files/myfile',
changes => 'set 01 "subversion-1.6"',
onlyif => 'match *[. =~ regex("^subversion-")] size == 0';
'Update line if present':
context => '/files/myfile',
changes => 'set *[. =~ regex("^subversion-")] "subversion-1.6"',
require => Augeas['Add line if missing'];
@raphink
raphink / augeas.rb
Last active December 20, 2015 21:19
Puppet::Type.type(:simpleline).provide(:augeas) do
desc "Uses Augeas API to update simple line conffiles"
include AugeasProviders::Provider
lens { 'Simplelines.lns' }
confine :feature => :augeas
#!/bin/sh
LOGS=$1
grep scope $LOGS | awk '{print $1" "$14}' | while read f l; do
echo $f: $(sed "${l}q;d" $f)
done