diff --git a/hieradata/common.yaml b/hieradata/common.yaml index da3106f..d07c72a 100644 --- a/hieradata/common.yaml +++ b/hieradata/common.yaml @@ -19,6 +19,9 @@ profiles::base::packages::common: - wget - zsh +profiles::base::scripts::scripts: + puppet: puppetwrapper.py + profiles::puppet::autosign::subnet_ranges: - '198.18.17.0/24' diff --git a/site/profiles/manifests/base.pp b/site/profiles/manifests/base.pp index 0f40f27..8e56160 100644 --- a/site/profiles/manifests/base.pp +++ b/site/profiles/manifests/base.pp @@ -23,6 +23,9 @@ class profiles::base ( ensure => 'installed', } + # include admin scripts + include profiles::base::scripts + # include the python class class { 'python': manage_python_package => true, diff --git a/site/profiles/manifests/base/scripts.pp b/site/profiles/manifests/base/scripts.pp new file mode 100644 index 0000000..fc0b3e8 --- /dev/null +++ b/site/profiles/manifests/base/scripts.pp @@ -0,0 +1,26 @@ +# This class can be included directly in node definitions or other classes. +# The preferred method for declaring the scripts is via Hiera. +# +# Here's an example Hiera configuration: +# +# profiles::base::scripts::scripts: +# script1: script1 +# script2: script2 +# +# This would deploy 'script1' and 'script2' to /usr/local/bin using their +# respective ERB templates in the profiles/base/scripts directory. +# +class profiles::base::scripts ( + Hash $scripts = {}, +) { + $scripts.each |$script_name, $template_name| { + file { "/usr/local/bin/${script_name}": + ensure => file, + owner => 'root', + group => 'root', + mode => '0755', + content => template("profiles/base/scripts/${template_name}.erb"), + } + } +} + diff --git a/site/profiles/templates/base/scripts/puppetwrapper.py.erb b/site/profiles/templates/base/scripts/puppetwrapper.py.erb new file mode 100644 index 0000000..57ca8b1 --- /dev/null +++ b/site/profiles/templates/base/scripts/puppetwrapper.py.erb @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import sys +import subprocess + +def main(): + # If "-E" is in the arguments, modify the following argument + args = sys.argv[1:] + if "-E" in args: + index = args.index("-E") + if index + 1 < len(args): # Check if there's another argument after "-E" + environment_value = args[index + 1] + # Replace \ and - with _ + modified_environment_value = environment_value.replace("\\", "_").replace("-", "_").replace("/","_") + args[index + 1] = modified_environment_value + + # Construct the full puppet command with the modified args + command = ["/opt/puppetlabs/bin/puppet"] + args + subprocess.run(command) + +if __name__ == "__main__": + main()