Merge pull request 'Added class to manage a default set of scripts' (#27) from neoloc/puppet_wrapper into develop

Reviewed-on: unkinben/puppet-prod#27
This commit is contained in:
Ben Vincent 2023-10-21 22:32:30 +09:30
commit aaee62afad
4 changed files with 54 additions and 0 deletions

View File

@ -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'

View File

@ -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,

View File

@ -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"),
}
}
}

View File

@ -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()