summaryrefslogtreecommitdiff
path: root/filter_plugins/config-parser.py
blob: c052a7ec86918a8ba29c2f360a58fe9c80b95bc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from functools import partial

from ansible import errors


def from_ini(data):
    try:
        import configparser
        config = configparser.ConfigParser()
        config.optionxform = lambda option: option
        config.read_string(data)
        return {s: dict(config.items(s)) for s in config.sections()}
    except Exception as e:
        raise errors.AnsibleFilterError("from_ini(): %s" % str(e))


class FilterModule(object):

    ''' config parser filters '''
    filter_map = {
        'from_ini': from_ini,
    }

    def filters(self):
        return self.filter_map