Browse Source

Make blacklisting configurable

Matthias Vogelgesang 10 years ago
parent
commit
f710280d85
1 changed files with 22 additions and 13 deletions
  1. 22 13
      library/blacklist

+ 22 - 13
library/blacklist

@@ -37,6 +37,12 @@ options:
         choices: [ present, absent ]
         description:
             - Whether the module should be present in the blacklist or absent.
+    blacklist_file:
+        required: false
+        description:
+            - If specified, use this blacklist file instead of
+              C(/etc/modprobe.d/blacklist-ansible.conf).
+        default: null
 '''
 
 EXAMPLES = '''
@@ -46,7 +52,7 @@ EXAMPLES = '''
 
 
 class Blacklist(object):
-    def __init__(self, module, filename='/etc/modprobe.d/blacklist-ansible.conf'):
+    def __init__(self, module, filename):
         if not os.path.exists(filename):
             open(filename, 'a').close()
 
@@ -95,21 +101,24 @@ class Blacklist(object):
 
 def main():
     module = AnsibleModule(
-        argument_spec={
-            'name': {'required': True},
-            'state': {'default': 'present', 'choices': ['present', 'absent']},
-        },
-        supports_check_mode=True,
+        argument_spec=dict(
+            name=dict(required=True),
+            state=dict(required=False, choices=['present', 'absent'],
+                       default='present'),
+            blacklist_file=dict(required=False, default=None)
+        ),
+        supports_check_mode=False,
     )
 
-    args = {
-        'changed': False,
-        'failed': False,
-        'name': module.params['name'],
-        'state': module.params['state'],
-    }
+    args = dict(changed=False, failed=False,
+                name=module.params['name'], state=module.params['state'])
+
+    filename = '/etc/modprobe.d/blacklist-ansible.conf'
+
+    if module.params['blacklist_file']:
+        filename = module.params['blacklist_file']
 
-    blacklist = Blacklist(args['name'])
+    blacklist = Blacklist(args['name'], filename)
 
     if blacklist.module_listed():
         if args['state'] == 'absent':