Initial commit
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
new file mode 100644
index 0000000..0d112d5
--- /dev/null
+++ b/CHANGELOG.rst
@@ -0,0 +1,13 @@
+reclass-formula
+===============
+
+0.0.2
+-----
+
+- Reloading of pillar within run
+- Kernel support for dynamic nodes
+
+0.0.1
+-----
+
+- Initial commit to Community form
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6f2b42f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2014-2015 tcp cloud a.s.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
\ No newline at end of file
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..a412413
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,52 @@
+
+=======
+reclass
+=======
+
+reclass is an “external node classifier” (ENC) as can be used with automation tools, such as Puppet, Salt, and Ansible. It is also a stand-alone tool for merging data sources recursively.
+
+Sample pillars
+==============
+
+Reclass storage with data fetched from git
+
+.. code-block:: yaml
+
+ reclass:
+ storage:
+ enabled: true
+ base_dir: /srv/reclass
+ data_source:
+ engine: git
+ address: git@repo.domain.com:reclass/reclass-project.git
+ revision: master
+
+Reclass storage with local data source
+
+.. code-block:: yaml
+
+ reclass:
+ storage:
+ enabled: true
+ base_dir: /srv/reclass
+ data_source:
+ engine: local
+
+Reclass storage with arbitrary class mappings
+
+.. code-block:: yaml
+
+ reclass:
+ storage:
+ enabled: true
+ ...
+ class_mappings:
+ - target: '\*'
+ class: default
+
+Read more
+=========
+
+* http://reclass.pantsfullofunix.net/index.html
+* http://reclass.pantsfullofunix.net/operations.html
+* http://ryandlane.com/blog/2014/12/10/reloading-grains-and-pillars-during-a-saltstack-run/
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..3b04cfb
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.2
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..121623b
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,11 @@
+salt-formula-reclass (0.2) trusty; urgency=medium
+
+ * First public release
+
+ -- Filip Pytloun <filip.pytloun@tcpcloud.eu> Tue, 06 Oct 2015 16:38:52 +0200
+
+salt-formula-reclass (0.1) trusty; urgency=medium
+
+ * Initial release
+
+ -- Ales Komarek <ales.komarek@tcpcloud.eu> Thu, 13 Aug 2015 23:23:41 +0200
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+9
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..a841dae
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,15 @@
+Source: salt-formula-reclass
+Maintainer: Ales Komarek <ales.komarek@tcpcloud.eu>
+Section: admin
+Priority: optional
+Build-Depends: debhelper (>= 9)
+Standards-Version: 3.9.6
+Homepage: http://www.tcpcloud.eu
+Vcs-Browser: https://github.com/tcpcloud/salt-formula-reclass
+Vcs-Git: https://github.com/tcpcloud/salt-formula-reclass.git
+
+Package: salt-formula-reclass
+Architecture: all
+Depends: ${misc:Depends}, salt-master, reclass
+Description: Reclass salt formula
+ Configure Reclass hierarchical data storage.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..240e2bf
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,15 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: salt-formula-reclass
+Upstream-Contact: Ales Komarek <ales.komarek@tcpcloud.eu>
+Source: https://github.com/tcpcloud/salt-formula-reclass
+
+Files: *
+Copyright: 2014-2015 tcp cloud a.s.
+License: Apache-2.0
+ Copyright (C) 2014-2015 tcp cloud a.s.
+ .
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ .
+ On a Debian system you can find a copy of this license in
+ /usr/share/common-licenses/Apache-2.0.
diff --git a/debian/docs b/debian/docs
new file mode 100644
index 0000000..d585829
--- /dev/null
+++ b/debian/docs
@@ -0,0 +1,3 @@
+README.rst
+CHANGELOG.rst
+VERSION
diff --git a/debian/install b/debian/install
new file mode 100644
index 0000000..785e668
--- /dev/null
+++ b/debian/install
@@ -0,0 +1,2 @@
+reclass/* /usr/share/salt-formulas/env/reclass/
+metadata/service/* /usr/share/salt-formulas/reclass/service/reclass/
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..abde6ef
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,5 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@
+
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..89ae9db
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (native)
diff --git a/metadata/service/storage/ansible.yml b/metadata/service/storage/ansible.yml
new file mode 100644
index 0000000..096cd9f
--- /dev/null
+++ b/metadata/service/storage/ansible.yml
@@ -0,0 +1,7 @@
+applications:
+- reclass
+parameters:
+ reclass:
+ storage:
+ enabled: true
+ base_dir: /srv/ansible/reclass
diff --git a/metadata/service/storage/salt.yml b/metadata/service/storage/salt.yml
new file mode 100644
index 0000000..22cdfd5
--- /dev/null
+++ b/metadata/service/storage/salt.yml
@@ -0,0 +1,12 @@
+applications:
+- reclass
+parameters:
+ reclass:
+ storage:
+ enabled: true
+ base_dir: /srv/salt/reclass
+ output: yaml
+ data_source:
+ engine: git
+ address: ${_param:reclass_data_repository}
+ branch: ${_param:reclass_data_revision}
diff --git a/reclass/files/node.yml b/reclass/files/node.yml
new file mode 100644
index 0000000..d35f09d
--- /dev/null
+++ b/reclass/files/node.yml
@@ -0,0 +1,17 @@
+{%- set node = salt['pillar.get']('reclass:storage:node:'+node_name) %}
+classes:
+{%- for class in node.classes %}
+- {{ class }}
+{%- endfor %}
+parameters:
+ _param:
+ {%- for param_name, param_value in node.params.iteritems() %}
+ {{ param_name }}: {{ param_value }}
+ {%- endfor %}
+ {{ node.get('kernel', 'linux') }}:
+ system:
+ name: {{ node.name }}
+ domain: {{ node.domain }}
+ {%- for param_name, param_value in node.get("parameters", {}).iteritems() %}
+ {{ param_name }}: {{ param_value }}
+ {%- endfor %}
diff --git a/reclass/files/reclass-config.yml b/reclass/files/reclass-config.yml
new file mode 100644
index 0000000..5fb1490
--- /dev/null
+++ b/reclass/files/reclass-config.yml
@@ -0,0 +1,11 @@
+{%- from "reclass/map.jinja" import storage with context %}
+storage_type: {{ storage.storage_type }}
+pretty_print: True
+output: {{ storage.get('output', 'json') }}
+inventory_base_uri: {{ storage.base_dir }}
+{%- if storage.class_mappings is defined %}
+class_mappings:
+{%- for mapping in storage.class_mappings %}
+- {{ mapping.target }} {{ mapping.class }}
+{%- endfor %}
+{%- endif %}
\ No newline at end of file
diff --git a/reclass/init.sls b/reclass/init.sls
new file mode 100644
index 0000000..e3ecb59
--- /dev/null
+++ b/reclass/init.sls
@@ -0,0 +1,7 @@
+
+{%- if pillar.reclass is defined %}
+include:
+{%- if pillar.reclass.storage is defined %}
+- reclass.storage
+{%- endif %}
+{%- endif %}
\ No newline at end of file
diff --git a/reclass/map.jinja b/reclass/map.jinja
new file mode 100644
index 0000000..02fab07
--- /dev/null
+++ b/reclass/map.jinja
@@ -0,0 +1,20 @@
+{%- set storage = salt['grains.filter_by']({
+ 'Debian': {
+ 'base_dir': '/etc/reclass/base',
+ 'pkgs': ['reclass', 'python-reclass'],
+ 'data_source': {
+ 'engine': 'local'
+ },
+ 'storage_type': 'yaml_fs',
+ 'version': '1.4.1',
+ },
+ 'RedHat': {
+ 'base_dir': '/etc/reclass/base',
+ 'pkgs': ['reclass', 'python-reclass'],
+ 'data_source': {
+ 'engine': 'local'
+ },
+ 'storage_type': 'yaml_fs',
+ 'version': '1.4.1',
+ },
+}, grain='os_family', merge=salt['pillar.get']('reclass:storage')) %}
diff --git a/reclass/storage/data.sls b/reclass/storage/data.sls
new file mode 100644
index 0000000..c804ecf
--- /dev/null
+++ b/reclass/storage/data.sls
@@ -0,0 +1,24 @@
+{%- from "reclass/map.jinja" import storage with context %}
+{%- if storage.enabled %}
+
+{%- if storage.data_source.engine == "git" %}
+
+reclass_data_source:
+ git.latest:
+ - name: {{ storage.data_source.address }}
+ - target: {{ storage.base_dir }}
+ - rev: {{ storage.data_source.branch }}
+ - reload_pillar: True
+
+{%- endif %}
+
+{%- if storage.data_source.engine == "local" %}
+
+reclass_data_dir:
+ file.managed:
+ - name: {{ storage.base_dir }}
+ - mode: 700
+
+{%- endif %}
+
+{%- endif %}
\ No newline at end of file
diff --git a/reclass/storage/init.sls b/reclass/storage/init.sls
new file mode 100644
index 0000000..5289258
--- /dev/null
+++ b/reclass/storage/init.sls
@@ -0,0 +1,8 @@
+{%- if pillar.reclass is defined %}
+include:
+- reclass.storage.service
+- reclass.storage.data
+{%- if pillar.reclass.storage.node is defined %}
+- reclass.storage.node
+{%- endif %}
+{%- endif %}
\ No newline at end of file
diff --git a/reclass/storage/node.sls b/reclass/storage/node.sls
new file mode 100644
index 0000000..5fcca8e
--- /dev/null
+++ b/reclass/storage/node.sls
@@ -0,0 +1,22 @@
+{%- from "reclass/map.jinja" import storage with context %}
+{%- if storage.enabled %}
+
+{{ storage.base_dir }}/nodes/_generated:
+ file.directory
+
+{%- for node_name, node in storage.node.iteritems() %}
+
+{{ storage.base_dir }}/nodes/_generated/{{ node.name }}.{{ node.domain }}.yml:
+ file.managed:
+ - source: salt://reclass/files/node.yml
+ - user: root
+ - group: root
+ - template: jinja
+ - defaults:
+ node_name: "{{ node_name }}"
+ - requires:
+ - git: {{ storage.data_source.address }}
+
+{%- endfor %}
+
+{%- endif %}
\ No newline at end of file
diff --git a/reclass/storage/service.sls b/reclass/storage/service.sls
new file mode 100644
index 0000000..31d33e8
--- /dev/null
+++ b/reclass/storage/service.sls
@@ -0,0 +1,19 @@
+{%- from "reclass/map.jinja" import storage with context %}
+{%- if storage.enabled %}
+
+reclass_conf_dir:
+ file.directory:
+ - name: /etc/reclass
+
+/etc/reclass/reclass-config.yml:
+ file.managed:
+ - source: salt://reclass/files/reclass-config.yml
+ - template: jinja
+ - require:
+ - file: reclass_conf_dir
+
+reclass_packages:
+ pkg.latest:
+ - names: {{ storage.pkgs }}
+
+{%- endif %}