summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorGordon Messmer <gordon@dragonsdawn.net>2014-09-11 11:22:03 -0700
committerGordon Messmer <gordon@dragonsdawn.net>2014-09-11 11:22:03 -0700
commit4462816a4a2c26ef7fc94f51b6485feb1ab44c27 (patch)
tree09c73c42e98d95f3ea28910d13c01ce3077003dc /doc
parent92f64c0aa166eca93cdf56e7e2e870100c3cb5bc (diff)
downloadbcfg2-4462816a4a2c26ef7fc94f51b6485feb1ab44c27.tar.gz
bcfg2-4462816a4a2c26ef7fc94f51b6485feb1ab44c27.tar.bz2
bcfg2-4462816a4a2c26ef7fc94f51b6485feb1ab44c27.zip
First pass at Jinja2 support for Cfg.
Diffstat (limited to 'doc')
-rw-r--r--doc/development/cfg.txt2
-rw-r--r--doc/server/plugins/generators/cfg.txt47
-rw-r--r--doc/server/plugins/generators/examples/jinja2/simple.txt53
3 files changed, 91 insertions, 11 deletions
diff --git a/doc/development/cfg.txt b/doc/development/cfg.txt
index f93bb42c7..4e967368b 100644
--- a/doc/development/cfg.txt
+++ b/doc/development/cfg.txt
@@ -64,9 +64,11 @@ Generators
.. autoclass:: Bcfg2.Server.Plugins.Cfg.CfgPlaintextGenerator.CfgPlaintextGenerator
.. autoclass:: Bcfg2.Server.Plugins.Cfg.CfgGenshiGenerator.CfgGenshiGenerator
.. autoclass:: Bcfg2.Server.Plugins.Cfg.CfgCheetahGenerator.CfgCheetahGenerator
+.. autoclass:: Bcfg2.Server.Plugins.Cfg.CfgJinja2Generator.CfgJinja2Generator
.. autoclass:: Bcfg2.Server.Plugins.Cfg.CfgEncryptedGenerator.CfgEncryptedGenerator
.. autoclass:: Bcfg2.Server.Plugins.Cfg.CfgEncryptedGenshiGenerator.CfgEncryptedGenshiGenerator
.. autoclass:: Bcfg2.Server.Plugins.Cfg.CfgEncryptedCheetahGenerator.CfgEncryptedCheetahGenerator
+.. autoclass:: Bcfg2.Server.Plugins.Cfg.CfgEncryptedJinja2Generator.CfgEncryptedJinja2Generator
.. autoclass:: Bcfg2.Server.Plugins.Cfg.CfgAuthorizedKeysGenerator.CfgAuthorizedKeysGenerator
Creators
diff --git a/doc/server/plugins/generators/cfg.txt b/doc/server/plugins/generators/cfg.txt
index 9ebbd2666..8e0bb7137 100644
--- a/doc/server/plugins/generators/cfg.txt
+++ b/doc/server/plugins/generators/cfg.txt
@@ -30,8 +30,8 @@ in ``Cfg/etc/passwd/passwd``, while the ssh pam module config file,
``/etc/pam.d/sshd``, goes in ``Cfg/etc/pam.d/sshd/sshd``. The reason for
the like-name directory is to allow multiple versions of each file to
exist, as described below. Note that these files are exact copies of what
-will appear on the client machine (except when using Genshi or Cheetah
-templating -- see below).
+will appear on the client machine (except when using templates -- see
+below).
Group-Specific Files
====================
@@ -242,6 +242,27 @@ comment to appear in the final config file.::
# This is a comment in my template which will be stripped when it's processed through Cheetah
\# This comment will appear in the generated config file.
+.. _server-plugins-generators-cfg-jinja2:
+
+Jinja2 Templates
+-----------------
+
+Jinja2 templates allow you to use the `jinja2 templating system
+<http://jinja.pocoo.org/>`_. Jinja2 templates should be
+named with a ``.jinja2`` extension, e.g.::
+
+ % ls Cfg/etc/motd
+ info.xml motd.jinja2
+
+Examples
+~~~~~~~~
+
+.. toctree::
+ :glob:
+ :maxdepth: 1
+
+ examples/jinja2/*
+
Inside Templates
----------------
@@ -263,10 +284,10 @@ Several variables are pre-defined inside templates:
| repo | The path to the Bcfg2 repository on the filesystem |
+-------------+--------------------------------------------------------+
| path | In Genshi templates, ``path`` is a synonym for |
-| | ``source_path``. In Cheetah templates, it's a synonym |
-| | for ``name``. For this reason, use of ``path`` is |
-| | discouraged, and it may be deprecated in a future |
-| | release. |
+| | ``source_path``. In Cheetah templates and Jinja2 |
+| | templates, it's a synonym for ``name``. For this |
+| | reason, use of ``path`` is discouraged, and it may be |
+| | deprecated in a future release. |
+-------------+--------------------------------------------------------+
To access these variables in a Genshi template, you can simply use the
@@ -274,6 +295,10 @@ name, e.g.::
Path to this file: ${name}
+Similarly, in a Jinja2 template::
+
+ Path to this file: {{ name }}
+
In a Cheetah template, the variables are properties of ``self``,
e.g.::
@@ -283,15 +308,15 @@ Notes on Using Templates
------------------------
Templates can be host and group specific as well. Deltas will not be
-processed for any Genshi or Cheetah base file.
+processed for any Genshi, Cheetah, or Jinja2 base file.
.. note::
If you are using templating in combination with host-specific
or group-specific files, you will need to ensure that the ``.genshi``
- or ``.cheetah`` extension is at the **end** of the filename. Using the
- examples from above for *host.example.com* and group *server* you would
- have the following::
+ ``.cheetah`` or ``.jinja2`` extension is at the **end** of the filename.
+ Using the examples from above for *host.example.com* and group *server*
+ you would have the following::
Cfg/etc/fstab/fstab.H_host.example.com.genshi
Cfg/etc/fstab/fstab.G50_server.cheetah
@@ -345,7 +370,7 @@ An encrypted file should end with ``.crypt``, e.g.::
Cfg/etc/foo.conf/foo.conf.crypt
Cfg/etc/foo.conf/foo.conf.G10_foo.crypt
-Encrypted Genshi or Cheetah templates can have the extensions in
+Encrypted Genshi, Cheetah, and Jinja2 templates can have the extensions in
either order, e.g.::
Cfg/etc/foo.conf/foo.conf.crypt.genshi
diff --git a/doc/server/plugins/generators/examples/jinja2/simple.txt b/doc/server/plugins/generators/examples/jinja2/simple.txt
new file mode 100644
index 000000000..59fc3b89c
--- /dev/null
+++ b/doc/server/plugins/generators/examples/jinja2/simple.txt
@@ -0,0 +1,53 @@
+.. -*- mode: rst -*-
+
+=========================
+ Basic Jinja2 Templates
+=========================
+
+This simple example demonstrates basic usage of Jinja2 templates.
+
+``/var/lib/bcfg2/Cfg/foo/foo.jinja2``
+
+.. code-block:: none
+
+ Hostname is {{ metadata.hostname }}
+ Filename is {{ path }}
+ Template is {{ source_path }}
+ Groups:
+ {% for group in metadata.groups -%}
+ * {{ group }}
+ {% endfor %}
+ Categories:
+ {% for category in metadata.categories -%}
+ * {{ category }} -- {{ metadata.categories[category] }}
+ {% endfor %}
+
+ Probes:
+ {% for probe in metadata.Probes -%}
+ * {{ probe }} -- {{ metadata.Probes[probe] }}
+ {% endfor %}
+
+Output
+======
+
+.. code-block:: xml
+
+ <Path type="file" name="/foo" owner="root" mode="0644" group="root">
+ Hostname is topaz.mcs.anl.gov
+ Filename is /foo
+ Template is /var/lib/bcfg2/Cfg/foo/foo.jinja2
+ Groups:
+ * desktop
+ * mcs-base
+ * ypbound
+ * workstation
+ * xserver
+ * debian-sarge
+ * debian
+ * a
+ Categories:
+ * test -- a
+
+ Probes:
+ * os -- debian
+ </Path>