Page MenuHomeDevCentral

D1253.id3225.diff
No OneTemporary

D1253.id3225.diff

diff --git a/_modules/node.py b/_modules/node.py
--- a/_modules/node.py
+++ b/_modules/node.py
@@ -115,3 +115,32 @@
salt * node.has_role devserver
'''
return role in list('roles', nodename)
+
+
+def get_wwwroot(nodename=None):
+ '''
+ A function to determine the wwwroot folder to use.
+
+ Returns a string depending of the FQDN.
+
+ CLI Example:
+
+ salt * node.get_wwwroot
+ '''
+ hostname = _get_property("hostname", nodename, None)
+
+ if hostname is None:
+ raise CommandExecutionError(
+ SaltCloudConfigError(
+ "Node {0} doesn't have a hostname property".format(nodename)
+ )
+ )
+
+ if hostname.count('.') < 2:
+ return "wwwroot/{0}/www".format(hostname)
+
+ fqdn = hostname.split(".")
+ return "wwwroot/{1}/{0}".format(
+ ".".join(fqdn[0:-2]),
+ ".".join(fqdn[-2:])
+ )
diff --git a/_tests/data/forests.yaml b/_tests/data/forests.yaml
--- a/_tests/data/forests.yaml
+++ b/_tests/data/forests.yaml
@@ -6,8 +6,10 @@
nodes:
egladil:
forest: lothlorien
+ hostname: egladil.lothlorien.forest
entwash:
forest: fangorn
+ hostname: entwash.node
shellgroups_ubiquity:
- ubiquity
diff --git a/_tests/modules/test_node.py b/_tests/modules/test_node.py
new file mode 100644
--- /dev/null
+++ b/_tests/modules/test_node.py
@@ -0,0 +1,24 @@
+import imp
+import unittest
+
+
+salt_test_case = imp.load_source('salt_test_case', "salt_test_case.py")
+node = imp.load_source('node', "../_modules/node.py")
+
+
+class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
+
+ def setUp(self):
+ self.initialize_mocks()
+ self.instance = node
+
+ self.mock_pillar('data/forests.yaml')
+
+ self.mock_grains()
+ self.grains['id'] = 'egladil'
+
+ def test_get_wwwroot(self):
+ self.assertEqual("wwwroot/lothlorien.forest/egladil",
+ node.get_wwwroot())
+ self.assertEqual("wwwroot/entwash.node/www",
+ node.get_wwwroot('entwash'))
diff --git a/roles/shellserver/eglide-website/init.sls b/roles/shellserver/eglide-website/init.sls
--- a/roles/shellserver/eglide-website/init.sls
+++ b/roles/shellserver/eglide-website/init.sls
@@ -10,21 +10,25 @@
# Deploy /opt/staging/wwwroot/eglide.org/www to www.eglide.org
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+{% set wwwroot = salt['node.get_wwwroot']() %}
+{% set wwwuser = "www-data" %}
+{% set wwwgroup = "www-data" %}
+
/var/www/html:
file.recurse:
- - source: salt://wwwroot/eglide.org/www
+ - source: salt://{{ wwwroot }}
- exclude_pat: E@.git
- include_empty: True
- clean: True
- - user: www-data
- - group: www-data
+ - user: {{ wwwuser }}
+ - group: {{ wwwgroup }}
- dir_mode: 711
- file_mode: 644
/var/wwwroot/paysannerebelle.com/robot/:
file.directory:
- user: hlp
- - group: www-data
+ - group: {{ wwwgroup }}
- dir_mode: 711
- makedirs: True
@@ -35,11 +39,11 @@
/var/log/www/eglide.org:
file.directory:
- user: root
- - group: www-data
+ - group: {{ wwwgroup }}
- dir_mode: 750
/var/log/www/paysannerebelle.com:
file.directory:
- user: hlp
- - group: www-data
+ - group: {{ wwwgroup }}
- dir_mode: 750

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 05:07 (15 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259563
Default Alt Text
D1253.id3225.diff (3 KB)

Event Timeline