Last active
August 29, 2015 14:04
-
-
Save ambakshi/0d88682189af6340a1b3 to your computer and use it in GitHub Desktop.
Awk script to extract class decls from pp files
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
#!/usr/bin/env gawk | |
# | |
# Only print stuff inside the puppet class: | |
#$0 ~ /^[ \t]*$/ {on = 0} | |
# | |
BEGIN { | |
cls_name=""; | |
} | |
# Match closing bracket for class | |
$0 ~ /^}[ \t]*$/ { | |
on = 0 | |
} | |
on { | |
print cls_name, $0 | |
} | |
# Capture class name and set on = 1 so we print | |
match($0, /^class[ \t]*([a-z:_]+)[ \t]*{[ \t]*$/, a) { | |
cls_name = a[1] | |
print "#", cls_name | |
on = 1 | |
} | |
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
#!/bin/bash | |
# | |
# On OSX you need to brew install coreutils because BSD's awk is lacking | |
# | |
gawk -f puppet-node-extract.awk test.pp |
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
# | |
# Sample puppet class | |
# | |
class aws::qa_env_conf { | |
case $::hostname { | |
/^qa-(\w+)-\d+$/: { | |
$game = $1 | |
} | |
} | |
file { '/root/.bashrc': | |
path => '/root/.bashrc', | |
source => [ | |
"puppet:///modules/aws/root/qa_${game}_bashrc", | |
'puppet:///modules/aws/root/qa_bashrc', | |
], | |
owner => root, | |
group => root, | |
mode => '0644', | |
} | |
file { '/root/.bash_profile': | |
path => '/root/.bash_profile', | |
source => [ | |
"puppet:///modules/aws/root/${::hostname}_bash_profile", | |
"puppet:///modules/aws/root/qa_${game}_bash_profile", | |
'puppet:///modules/aws/root/qa_bash_profile', | |
], | |
owner => root, | |
group => root, | |
mode => '0744', | |
} | |
file { '/root/.bash_alias': | |
path => '/root/.bash_alias', | |
source => 'puppet:///modules/aws/root/bash_alias', | |
owner => root, | |
group => root, | |
mode => '0744', | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment