diff options
Diffstat (limited to 'modules/django_application')
3 files changed, 55 insertions, 0 deletions
diff --git a/modules/django_application/files/django_add_permission_to_group.py b/modules/django_application/files/django_add_permission_to_group.py new file mode 100644 index 00000000..c5edc31c --- /dev/null +++ b/modules/django_application/files/django_add_permission_to_group.py @@ -0,0 +1,11 @@ +#!/usr/bin/python +import sys +group_name = sys.argv[1] +permission = sys.argv[2] + +from django.contrib.auth.models import Group,Permission +g = Group.objects.get(name=group_name) +p = Permission.objects.get(codename=permission) + +g.permissions.add(p) +g.save() diff --git a/modules/django_application/files/django_create_group.py b/modules/django_application/files/django_create_group.py new file mode 100644 index 00000000..69079f66 --- /dev/null +++ b/modules/django_application/files/django_create_group.py @@ -0,0 +1,12 @@ +#!/usr/bin/python +import sys +group_name = sys.argv[1] + +from django.contrib.auth.models import Group +try: + group = Group.objects.get(name=group_name) +except Group.DoesNotExist: + group = Group.objects.create(name=group_name) + group.save() + + diff --git a/modules/django_application/manifests/init.pp b/modules/django_application/manifests/init.pp index 522f4472..d8bedbef 100644 --- a/modules/django_application/manifests/init.pp +++ b/modules/django_application/manifests/init.pp @@ -15,4 +15,36 @@ class django_application { source => "puppet:///modules/django_application/custom_backend.py", notify => Service['apache'] } + + define script() { + file { $name: + path => "/usr/local/bin/$name", + ensure => present, + owner => root, + group => root, + mode => 755, + source => "puppet:///modules/django_application/$name", + } + } + + script { ['django_create_group.py','django_add_permission_to_group.py']: + } + + define create_group($path,$module) { + exec { "/usr/local/bin/django_create_group.py $name": + user => root, + environment => ["DJANGO_SETTINGS_MODULE=$module.settings", + "PYTHONPATH=$path" ], + require => Django_application::Script['django_create_group.py'] + } + } + + define add_permission_to_group($path,$module,$group) { + exec { "/usr/local/bin/django_add_permission_to_group.py $group $name": + user => root, + environment => ["DJANGO_SETTINGS_MODULE=$module.settings", + "PYTHONPATH=$path" ], + require => Django_application::Script['django_add_permission_to_group.py'] + } + } } |