Porting ini lookup plugin against ansible v2.
This commit is contained in:
parent
09d257e637
commit
07fcb50b9b
1 changed files with 11 additions and 9 deletions
|
@ -14,19 +14,19 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
from ansible import utils, errors
|
|
||||||
import StringIO
|
import StringIO
|
||||||
import os
|
import os
|
||||||
import codecs
|
import codecs
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class LookupModule(object):
|
from ansible.errors import *
|
||||||
|
from ansible.plugins.lookup import LookupBase
|
||||||
|
|
||||||
def __init__(self, basedir=None, **kwargs):
|
class LookupModule(LookupBase):
|
||||||
self.basedir = basedir
|
|
||||||
self.cp = ConfigParser.ConfigParser()
|
|
||||||
|
|
||||||
def read_properties(self, filename, key, dflt, is_regexp):
|
def read_properties(self, filename, key, dflt, is_regexp):
|
||||||
config = StringIO.StringIO()
|
config = StringIO.StringIO()
|
||||||
|
@ -51,13 +51,15 @@ class LookupModule(object):
|
||||||
return dflt
|
return dflt
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def run(self, terms, inject=None, **kwargs):
|
def run(self, terms, variables=None, **kwargs):
|
||||||
|
|
||||||
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
|
|
||||||
|
|
||||||
if isinstance(terms, basestring):
|
if isinstance(terms, basestring):
|
||||||
terms = [ terms ]
|
terms = [ terms ]
|
||||||
|
|
||||||
|
basedir = self.get_basedir(variables)
|
||||||
|
self.basedir = basedir
|
||||||
|
self.cp = ConfigParser.ConfigParser()
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
for term in terms:
|
for term in terms:
|
||||||
params = term.split()
|
params = term.split()
|
||||||
|
@ -80,7 +82,7 @@ class LookupModule(object):
|
||||||
except (ValueError, AssertionError), e:
|
except (ValueError, AssertionError), e:
|
||||||
raise errors.AnsibleError(e)
|
raise errors.AnsibleError(e)
|
||||||
|
|
||||||
path = utils.path_dwim(self.basedir, paramvals['file'])
|
path = self._loader.path_dwim_relative(basedir, 'files', paramvals['file'])
|
||||||
if paramvals['type'] == "properties":
|
if paramvals['type'] == "properties":
|
||||||
var = self.read_properties(path, key, paramvals['default'], paramvals['re'])
|
var = self.read_properties(path, key, paramvals['default'], paramvals['re'])
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue