Add module replacer capability for powershell files.

This commit is contained in:
Michael DeHaan 2014-06-17 12:30:34 -05:00
parent 9c7ea82ad2
commit 627ff30a6f
3 changed files with 48 additions and 2 deletions

View file

@ -29,6 +29,7 @@ from ansible import constants as C
REPLACER = "#<<INCLUDE_ANSIBLE_MODULE_COMMON>>"
REPLACER_ARGS = "\"<<INCLUDE_ANSIBLE_MODULE_ARGS>>\""
REPLACER_COMPLEX = "\"<<INCLUDE_ANSIBLE_MODULE_COMPLEX_ARGS>>\""
REPLACER_WINDOWS = "# POWERSHELL_COMMON"
class ModuleReplacer(object):
@ -54,6 +55,10 @@ class ModuleReplacer(object):
All modules are required to import at least basic, though there will also
be other snippets.
# POWERSHELL_COMMON will also map to
{{ include 'powershell.ps1' }}
"""
# ******************************************************************************
@ -97,6 +102,10 @@ class ModuleReplacer(object):
if REPLACER in line:
output.write(self.slurp(os.path.join(self.snippet_path, "basic.py")))
snippet_names.append('basic')
if REPLACER_WINDOWS in line:
ps_data = self.slurp(os.path.join(self.snippet_path, "powershell.ps1"))
output.write(ps_data)
snippet_names.append('powershell')
elif line.startswith('from ansible.module_utils.'):
tokens=line.split(".")
import_error = False
@ -116,8 +125,14 @@ class ModuleReplacer(object):
output.write(line)
output.write("\n")
if len(snippet_names) > 0 and not 'basic' in snippet_names:
raise errors.AnsibleError("missing required import in %s: from ansible.module_utils.basic import *" % module_path)
if not module_path.endswith(".ps1"):
# Unixy modules
if len(snippet_names) > 0 and not 'basic' in snippet_names:
raise errors.AnsibleError("missing required import in %s: from ansible.module_utils.basic import *" % module_path)
else:
# Windows modules
if len(snippet_names) > 0 and not 'powershell' in snippet_names:
raise errors.AnsibleError("missing required import in %s: # POWERSHELL_COMMON" % module_path)
return (output.getvalue(), module_style)