Added class to manage a default set of scripts
- included scripts into profiles::base - updated hiera with list of scripts to create and their template name - created template for a puppet wrapper
This commit is contained in:
parent
c1ddb00cbb
commit
116342bdaa
@ -21,6 +21,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'
|
||||||
|
|
||||||
|
|||||||
@ -17,8 +17,12 @@ class profiles::base (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# install common required applications
|
||||||
class { 'profiles::base::packages':
|
class { 'profiles::base::packages':
|
||||||
packages => hiera('profiles::base::packages::common'),
|
packages => hiera('profiles::base::packages::common'),
|
||||||
ensure => 'installed',
|
ensure => 'installed',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# include admin scripts
|
||||||
|
include profiles::base::scripts
|
||||||
}
|
}
|
||||||
|
|||||||
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