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:
commit
aaee62afad
@ -19,6 +19,9 @@ profiles::base::packages::common:
|
|||||||
- wget
|
- wget
|
||||||
- zsh
|
- zsh
|
||||||
|
|
||||||
|
profiles::base::scripts::scripts:
|
||||||
|
puppet: puppetwrapper.py
|
||||||
|
|
||||||
profiles::puppet::autosign::subnet_ranges:
|
profiles::puppet::autosign::subnet_ranges:
|
||||||
- '198.18.17.0/24'
|
- '198.18.17.0/24'
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,9 @@ class profiles::base (
|
|||||||
ensure => 'installed',
|
ensure => 'installed',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# include admin scripts
|
||||||
|
include profiles::base::scripts
|
||||||
|
|
||||||
# include the python class
|
# include the python class
|
||||||
class { 'python':
|
class { 'python':
|
||||||
manage_python_package => true,
|
manage_python_package => true,
|
||||||
|
|||||||
26
site/profiles/manifests/base/scripts.pp
Normal file
26
site/profiles/manifests/base/scripts.pp
Normal 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"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
22
site/profiles/templates/base/scripts/puppetwrapper.py.erb
Normal file
22
site/profiles/templates/base/scripts/puppetwrapper.py.erb
Normal 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()
|
||||||
Loading…
Reference in New Issue
Block a user