Merge pull request #6 from tcpcloud/config

LGTM
diff --git a/jenkins/files/credentials.xml b/jenkins/files/credentials.xml
index 4451ad4..8e3da7b 100644
--- a/jenkins/files/credentials.xml
+++ b/jenkins/files/credentials.xml
@@ -1,4 +1,4 @@
-{%- from "jenkins/map.jinja" import master with context %}
+{%- from "jenkins/map.jinja" import master with context -%}
 <?xml version='1.0' encoding='UTF-8'?>
 <com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="credentials@2.1.4">
   <domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash">
@@ -24,7 +24,7 @@
                 <username>{{ credential.username }}</username>
                 <passphrase>{{ credential.password_hash }}</passphrase>
                 <privateKeySource class="com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource">
-                    <privateKey> {{ credential.key }}</privateKey>
+                    <privateKey>{{ credential.key }}</privateKey>
                 </privateKeySource>
             </com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey>
             {%- endif %}
@@ -32,4 +32,4 @@
       </java.util.concurrent.CopyOnWriteArrayList>
     </entry>
   </domainCredentialsMap>
-</com.cloudbees.plugins.credentials.SystemCredentialsProvider>
\ No newline at end of file
+</com.cloudbees.plugins.credentials.SystemCredentialsProvider>
diff --git a/jenkins/files/hudson.model.UpdateCenter.xml b/jenkins/files/hudson.model.UpdateCenter.xml
index 7ea703a..571853e 100644
--- a/jenkins/files/hudson.model.UpdateCenter.xml
+++ b/jenkins/files/hudson.model.UpdateCenter.xml
@@ -1,8 +1,8 @@
-{%- from "jenkins/map.jinja" import master with context %}
+{%- from "jenkins/map.jinja" import master with context -%}
 <?xml version='1.0' encoding='UTF-8'?>
 <sites>
   <site>
     <id>default</id>
     <url>{{ master.update_site_url }}</url>
   </site>
-</sites>
\ No newline at end of file
+</sites>
diff --git a/jenkins/files/hudson.tasks.Mailer.xml b/jenkins/files/hudson.tasks.Mailer.xml
index 0eecebe..ab60d4d 100644
--- a/jenkins/files/hudson.tasks.Mailer.xml
+++ b/jenkins/files/hudson.tasks.Mailer.xml
@@ -1,5 +1,5 @@
-{%- from "jenkins/map.jinja" import master with context %}
-{%- if master.email.engine == "smtp" %}
+{%- from "jenkins/map.jinja" import master with context -%}
+{%- if master.email.engine == "smtp" -%}
 <?xml version='1.0' encoding='UTF-8'?>
 <hudson.tasks.Mailer_-DescriptorImpl plugin="mailer@1.18">
   <smtpAuthUsername>{{ master.email.user }}</smtpAuthUsername>
@@ -9,4 +9,4 @@
   <smtpPort>{{ master.email.port }}</smtpPort>
   <charset>UTF-8</charset>
 </hudson.tasks.Mailer_-DescriptorImpl>
-{% endif %}
\ No newline at end of file
+{% endif %}
diff --git a/jenkins/files/jenkins-slave b/jenkins/files/jenkins-slave
index 351e015..1d27640 100644
--- a/jenkins/files/jenkins-slave
+++ b/jenkins/files/jenkins-slave
@@ -36,7 +36,7 @@
 # Name of slave configuration to use at JENKINS_URL
 # Override if it need to be something other than the
 # hostname of the server the slave is running on.
-JENKINS_HOSTNAME="{{ slave.hostname }}"
+JENKINS_HOSTNAME="{{ slave.hostname|default(grains.fqdn) }}"
 
 # Log file location for use in Debian init script
 JENKINS_SLAVE_LOG=/var/log/jenkins/$NAME.log
diff --git a/jenkins/files/scriptApproval.xml b/jenkins/files/scriptApproval.xml
index 25d9528..969ae43 100644
--- a/jenkins/files/scriptApproval.xml
+++ b/jenkins/files/scriptApproval.xml
@@ -1,4 +1,4 @@
-{%- from "jenkins/map.jinja" import master with context %}
+{%- from "jenkins/map.jinja" import master with context -%}
 <?xml version='1.0' encoding='UTF-8'?>
 <scriptApproval plugin="script-security@1.22">
   <approvedScriptHashes/>
diff --git a/jenkins/files/slave/default b/jenkins/files/slave/default
index e5ab906..7bfbade 100644
--- a/jenkins/files/slave/default
+++ b/jenkins/files/slave/default
@@ -38,7 +38,7 @@
 # Name of slave configuration to use at JENKINS_URL
 # Override if it need to be something other than the
 # hostname of the server the slave is running on.
-JENKINS_HOSTNAME="{{ slave.hostname }}"
+JENKINS_HOSTNAME="{{ slave.hostname|default(grains.fqdn) }}"
 
 # Log file location for use in Debian init script
 JENKINS_SLAVE_LOG=/var/log/jenkins/$NAME.log
diff --git a/jenkins/map.jinja b/jenkins/map.jinja
index 5118998..eb8fbbc 100644
--- a/jenkins/map.jinja
+++ b/jenkins/map.jinja
@@ -4,15 +4,17 @@
         'pkgs': ['jenkins'],
         'service': 'jenkins',
         'config': '/etc/default/jenkins',
+        'home': '/var/lib/jenkins',
         'update_site_url': 'http://updates.jenkins-ci.org/update-center.json'
     },
     'RedHat': {
         'pkgs': ['jenkins'],
         'service': 'jenkins',
         'config': '/etc/sysconfig/jenkins',
+        'home': '/var/lib/jenkins',
         'update_site_url': 'http://updates.jenkins-ci.org/update-center.json'
     },
-}, merge=salt['pillar.get']('jenkins:master')) %}
+}, merge=pillar.jenkins.get('master', {})) %}
 
 {% set job_builder = salt['grains.filter_by']({
     'Debian': {
@@ -35,30 +37,22 @@
             'engine': 'pkg'
         }
     },
-}, merge=salt['pillar.get']('jenkins:job_builder')) %}
-
-{% if pillar.system is defined %}
-{%- set hostname = pillar.system.name %}
-{%- else %}
-{%- set hostname = pillar.linux.system.name+'.'+pillar.linux.system.domain %}
-{%- endif %}
+}, merge=pillar.jenkins.get('job_builder', {})) %}
 
 {% set slave = salt['grains.filter_by']({
     'Debian': {
         'pkgs': ['jenkins-slave'],
         'init_script': '/etc/init.d/jenkins-slave',
         'service': 'jenkins-slave',
-        'hostname': hostname,
         'config': '/etc/default/jenkins-slave',
     },
     'RedHat': {
         'pkgs': ['jenkins-slave'],
         'init_script': '/etc/init.d/jenkins-slave',
-        'hostname': hostname,
         'service': 'jenkins-slave',
         'config': '/etc/sysconfig/jenkins-slave',
     },
-}, merge=salt['pillar.get']('jenkins:slave')) %}
+}, merge=pillar.jenkins.get('slave', {})) %}
 
 {% set job_status = {
     'SUCCESS': {
@@ -84,4 +78,4 @@
             'jenkins_jobs_root': '/var/cache/salt/minion/jenkins/jobs',
         }
     },
-}, merge=salt['pillar.get']('jenkins:client')) %}
+}, merge=pillar.jenkins.get('client', {})) %}
diff --git a/jenkins/master/plugin.sls b/jenkins/master/plugin.sls
index 6c618e9..7eb8403 100644
--- a/jenkins/master/plugin.sls
+++ b/jenkins/master/plugin.sls
@@ -1,6 +1,6 @@
 {% from "jenkins/map.jinja" import master with context %}
 
-/var/lib/jenkins/updates:
+{{ master.home }}/updates:
   file.directory:
   - user: jenkins
   - group: nogroup
@@ -18,7 +18,7 @@
 install_jenkins_plugin_{{ plugin.name }}:
   cmd.run:
   - name: java -jar jenkins-cli.jar -s http://localhost:{{ master.http.port }} install-plugin --username admin --password {{ master.user.admin.password }} {{ plugin.name }}
-  - unless: "[ -d /var/lib/jenkins/plugins/{{ plugin.name }} ]"
+  - unless: "[ -d {{ master.home }}/plugins/{{ plugin.name }} ]"
   - cwd: /root
   - require:
     - cmd: setup_jenkins_cli
diff --git a/jenkins/master/service.sls b/jenkins/master/service.sls
index e923e25..fc053ff 100644
--- a/jenkins/master/service.sls
+++ b/jenkins/master/service.sls
@@ -20,7 +20,7 @@
   - require:
     - pkg: jenkins_packages
 
-/var/lib/jenkins/config.xml:
+{{ master.home }}/config.xml:
   file.managed:
   {%- if master.get('no_config', False) == False %}
   - source: salt://jenkins/files/config.xml
@@ -32,7 +32,7 @@
 
 {%- if master.update_site_url is defined %}
 
-/var/lib/jenkins/hudson.model.UpdateCenter.xml:
+{{ master.home }}/hudson.model.UpdateCenter.xml:
   file.managed:
   - source: salt://jenkins/files/hudson.model.UpdateCenter.xml
   - template: jinja
@@ -44,7 +44,7 @@
 
 {%- if master.approved_scripts is defined %}
 
-/var/lib/jenkins/scriptApproval.xml:
+{{ master.home }}/scriptApproval.xml:
   file.managed:
   - source: salt://jenkins/files/scriptApproval.xml
   - template: jinja
@@ -56,7 +56,7 @@
 
 {%- if master.email is defined %}
 
-/var/lib/jenkins/hudson.tasks.Mailer.xml:
+{{ master.home }}/hudson.tasks.Mailer.xml:
   file.managed:
   - source: salt://jenkins/files/hudson.tasks.Mailer.xml
   - template: jinja
@@ -68,7 +68,7 @@
 
 {%- if master.credentials is defined %}
 
-/var/lib/jenkins/credentials.xml:
+{{ master.home }}/credentials.xml:
   file.managed:
   - source: salt://jenkins/files/credentials.xml
   - template: jinja
@@ -97,7 +97,7 @@
   - name: {{ master.service }}
   - watch:
     - file: jenkins_{{ master.config }}
-    - file: /var/lib/jenkins/config.xml
-    - file: /var/lib/jenkins/hudson.model.UpdateCenter.xml
+    - file: {{ master.home }}/config.xml
+    - file: {{ master.home }}/hudson.model.UpdateCenter.xml
 
 {%- endif %}
diff --git a/jenkins/master/user.sls b/jenkins/master/user.sls
index cd29822..1c262ce 100644
--- a/jenkins/master/user.sls
+++ b/jenkins/master/user.sls
@@ -2,16 +2,16 @@
 
 {%- for user_name, user in master.user.iteritems() %}
 
-/var/lib/jenkins/users/{{ user_name }}:
+{{ master.home }}/users/{{ user_name }}:
   file.directory:
   - makedirs: true
 
-/var/lib/jenkins/users/{{ user_name }}/config.xml:
+{{ master.home }}/users/{{ user_name }}/config.xml:
   file.managed:
   - source: salt://jenkins/files/config.xml.user
   - template: jinja
   - require:
-    - file: /var/lib/jenkins/users/{{ user_name }}
+    - file: {{ master.home }}/users/{{ user_name }}
   - defaults:
       user_name: "{{ user_name }}"
   - watch_in:
diff --git a/jenkins/meta/backupninja.yml b/jenkins/meta/backupninja.yml
index 31bfb17..ac20916 100644
--- a/jenkins/meta/backupninja.yml
+++ b/jenkins/meta/backupninja.yml
@@ -1,5 +1,6 @@
+{%- from "jenkins/map.jinja" import master with context -%}
 backup:
   jenkins:
     fs_includes:
-    - /var/lib/jenkins
+    - {{ master.home }}
     fs_excludes: []
diff --git a/jenkins/meta/config.yml b/jenkins/meta/config.yml
new file mode 100644
index 0000000..db12201
--- /dev/null
+++ b/jenkins/meta/config.yml
@@ -0,0 +1,45 @@
+config:
+  {%- if pillar.jenkins.master is defined %}
+  {%- from "jenkins/map.jinja" import master with context %}
+
+  {%- if master.get('no_config', True) == False %}
+  config.xml:
+    path: {{ master.home }}/config.xml
+    source: "salt://jenkins/files/config.xml"
+    template: jinja
+  {%- endif %}
+
+  {%- if master.update_site_url is defined %}
+  hudson.model.UpdateCenter.xml:
+    path: {{ master.home }}/hudson.model.UpdateCenter.xml
+    source: "salt://jenkins/files/hudson.model.UpdateCenter.xml"
+    template: jinja
+  {%- endif %}
+
+  {%- if master.approved_scripts is defined %}
+  scriptApproval.xml:
+    path: {{ master.home }}/scriptApproval.xml
+    source: "salt://jenkins/files/scriptApproval.xml"
+    template: jinja
+  {%- endif %}
+
+  {%- if master.email is defined %}
+  hudson.tasks.Mailer.xml:
+    path: {{ master.home }}/hudson.tasks.Mailer.xml
+    source: "salt://jenkins/files/hudson.tasks.Mailer.xml"
+    template: jinja
+  {%- endif %}
+
+  {%- if master.credentials is defined %}
+  credentials.xml:
+    path: {{ master.home }}/credentials.xml
+    source: "salt://jenkins/files/credentials.xml"
+    template: jinja
+  {%- endif %}
+
+  {%- endif %}
+
+
+{#-
+  vim: syntax=jinja
+-#}
diff --git a/metadata/service/support.yml b/metadata/service/support.yml
index 7ecb726..785dd4f 100644
--- a/metadata/service/support.yml
+++ b/metadata/service/support.yml
@@ -11,3 +11,5 @@
         enabled: true
       backupninja:
         enabled: true
+      config:
+        enabled: true