Permalink
Browse files

Add shell provisioner option

This can be used with extern, but also since scripts can be anywhere,
you must explicitly list in the omv.yaml file which scripts you want to
run. You can specify the path to a script or include a script inline in
the yaml file.
  • Loading branch information...
1 parent aa764ae commit cec25b9a9c17a81956cc6457706bab0b358a9708 @purpleidea committed Jul 2, 2015
View
@@ -12,6 +12,7 @@
directory: ansible-simple1
:puppet: false
:classes: []
+:shell: []
:docker: false
:kubernetes: false
:ansible:
View
@@ -8,6 +8,7 @@
:extern: []
:puppet: false
:classes: []
+:shell: []
:docker: false
:kubernetes: false
:ansible: []
@@ -12,6 +12,7 @@
directory: docker-simple1
:puppet: false
:classes: []
+:shell: []
:docker: []
:kubernetes: false
:ansible: []
@@ -16,6 +16,7 @@
directory: kube-simple1
:puppet: false
:classes: []
+:shell: []
:docker: []
:kubernetes:
applications:
@@ -12,6 +12,7 @@
directory: Fedora-Dockerfiles
:puppet: false
:classes: []
+:shell: []
:docker:
images: []
files:
@@ -12,6 +12,7 @@
directory: kubernetes
:puppet: false
:classes: []
+:shell: []
:docker: false
:kubernetes: false
:ansible:
@@ -16,6 +16,7 @@
directory: kube-simple1
:puppet: false
:classes: []
+:shell: []
:docker: []
:kubernetes:
applications:
View
@@ -16,6 +16,7 @@
directory: fakeapp2
:puppet: false
:classes: []
+:shell: []
:docker: []
:kubernetes:
master: omv0
@@ -30,6 +30,7 @@
- puppet
vrrp: true
vip: 192.168.123.3
+:shell: []
:docker: false
:kubernetes: false
:ansible: []
View
@@ -8,6 +8,7 @@
:extern: []
:puppet: false
:classes: []
+:shell: []
:docker: false
:kubernetes: false
:ansible: []
View
@@ -0,0 +1,36 @@
+---
+:domain: example.com
+:network: 192.168.123.0/24
+:image: centos-7.1
+:boxurlprefix: ''
+:sync: rsync
+:folder: ''
+:extern:
+- type: git
+ system: shell
+ repository: https://github.com/purpleidea/shell-simple1
+ directory: shell-simple1
+:puppet: false
+:classes: []
+:shell:
+- shell-simple1/hello1.sh
+- shell-simple1/hello2.py
+- path: shell-simple1/subdirectory/hello3.sh
+ once: false
+- script: echo hello world > /tmp/hello4
+ once: true
+:docker: []
+:kubernetes: false
+:ansible: []
+:playbook: []
+:cachier: false
+:vms: []
+:namespace: omv
+:count: 1
+:username: ''
+:password: ''
+:poolid: true
+:repos: []
+:update: false
+:comment: simple shell run example
+:reallyrm: false
View
@@ -73,6 +73,7 @@ folder = '' # default folder prefix
extern = [] # default external module definitions
puppet = false # default use of puppet or not
classes = [] # default list or hash of classes to include
+shell = [] # default list of shell scripts to run
docker = false # default use of docker or not
kubernetes = false # default use of kubernetes or not
ansible = [] # default ansible group list
@@ -194,6 +195,7 @@ if File.exist?(f)
extern = settings[:extern]
puppet = settings[:puppet]
classes = settings[:classes]
+ shell = settings[:shell]
docker = settings[:docker]
kubernetes = settings [:kubernetes]
ansible = settings[:ansible]
@@ -286,6 +288,15 @@ while skip < ARGV.length
classes = []
end
+ elsif ARGV[skip].start_with?(arg='--omv-shell=')
+ v = ARGV.delete_at(skip).dup
+ v.slice! arg
+
+ if v.is_a?(String) and v.include? ',' and v.split(',').length > 0
+ shell = v.split(',')
+ else
+ shell = []
+ end
elsif ARGV[skip].start_with?(arg='--omv-docker=')
v = ARGV.delete_at(skip).dup
v.slice! arg
@@ -462,6 +473,7 @@ settings = {
:extern => extern,
:puppet => puppet,
:classes => classes,
+ :shell => shell,
:docker => docker,
:kubernetes => kubernetes,
:ansible => ansible,
@@ -575,6 +587,7 @@ folder = '' if folder.start_with?('/') # only relative paths are allowed...
#puts "folder is: #{folder}" # debug
puppet_basedir = File.join(projectdir, folder, 'puppet/', 'modules/')
+shell_basedir = File.join(projectdir, folder, 'shell/')
# NOTE: i called the ansible child dir 'modules' because i didn't know
# what to call it. Suggestions welcome! It's not really 'playbooks' or
# 'roles' really, so it's 'modules' until something better comes along
@@ -586,6 +599,7 @@ ktemplates_basedir = File.join(projectdir, folder, 'kubernetes/', 'templates/')
# mkdir in case these folders are missing
mkdirp = 'mkdir -p'
mkdirp += " #{puppet_basedir}"
+mkdirp += " #{shell_basedir}"
mkdirp += " #{ansible_basedir}"
mkdirp += " #{docker_basedir}"
mkdirp += " #{kubernetes_basedir}"
@@ -594,6 +608,7 @@ mkdirp += " #{ktemplates_basedir}"
native = [] # native files
native += `cd "#{puppet_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
+native += `cd "#{shell_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
native += `cd "#{ansible_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
native += `cd "#{docker_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
native += `cd "#{kubernetes_basedir}" && (git status &> /dev/null) && git ls-files`.strip.split("\n")
@@ -605,6 +620,8 @@ if extern.length > 0
s = i.fetch('system', nil) # puppet, ansible, and so on...
if s == 'puppet'
basedir = puppet_basedir
+ elsif s == 'shell'
+ basedir = shell_basedir
elsif s == 'ansible'
basedir = ansible_basedir
elsif s == 'docker'
@@ -667,6 +684,7 @@ end
# clean up any directories or files that shouldn't be present
(
Dir.glob(puppet_basedir+'*') +
+ Dir.glob(shell_basedir+'*') +
Dir.glob(ansible_basedir+'*') +
Dir.glob(docker_basedir+'*') +
Dir.glob(kubernetes_basedir+'*') +
@@ -804,6 +822,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vm_docker = array_values_to_array_of_hashes(vm_docker)
vm_puppet = x.fetch(:puppet, puppet) # get value
vm_classes = x.fetch(:classes, classes)
+ vm_shell = x.fetch(:shell, shell) # get value
vm_poolid = x.fetch(:poolid, poolid) # get value
vm_repos = x.fetch(:repos, repos) # get value
vm_playbook = x.fetch(:playbook, playbook) # get value
@@ -978,6 +997,35 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end
end
+ # custom shell provisioner
+ # TODO: support running first/last as a setting
+ if vm_shell.is_a?(Array)
+ vm_shell.each do |sf|
+ shell_once = false
+ if sf.is_a?(Hash)
+ shell_once = sf.fetch('once', shell_once) # get value
+ si = sf.fetch('script', nil)
+ if not(si.nil?)
+ if not(shell_once) or (shell_once and not(File.exists?(fv)))
+ vm.vm.provision 'shell', inline: "#{si}"
+ end
+ next
+ end
+
+ sx = sf.fetch('path', '')
+ elsif sf.is_a?(String)
+ sx = sf
+ end
+
+ sx = File.join(shell_basedir, sx)
+ if File.exists?(sx) and not(File.directory?(sx)) and File.executable?(sx)
+ if not(shell_once) or (shell_once and not(File.exists?(fv)))
+ vm.vm.provision 'shell', path: "#{sx}"
+ end
+ end
+ end
+ end
+
# TODO: remove this chunk?
# ensure the $namespace module is present for provisioning...
if (puppet and vm_puppet and h == 'puppet') and (provision.is_a?(TrueClass) or (provision.is_a?(Array) and provision.include?('puppet')))
View
@@ -0,0 +1,2 @@
+Put your shell scripts in here! :)
+

0 comments on commit cec25b9

Please sign in to comment.