Add module replacer capability for powershell files.
This commit is contained in:
parent
9c7ea82ad2
commit
627ff30a6f
3 changed files with 48 additions and 2 deletions
|
@ -3,6 +3,7 @@ include examples/hosts
|
||||||
include examples/ansible.cfg
|
include examples/ansible.cfg
|
||||||
graft examples/playbooks
|
graft examples/playbooks
|
||||||
include packaging/distutils/setup.py
|
include packaging/distutils/setup.py
|
||||||
|
include lib/ansible/module_common/*.ps1
|
||||||
recursive-include docs *
|
recursive-include docs *
|
||||||
recursive-include library *
|
recursive-include library *
|
||||||
include Makefile
|
include Makefile
|
||||||
|
|
|
@ -29,6 +29,7 @@ from ansible import constants as C
|
||||||
REPLACER = "#<<INCLUDE_ANSIBLE_MODULE_COMMON>>"
|
REPLACER = "#<<INCLUDE_ANSIBLE_MODULE_COMMON>>"
|
||||||
REPLACER_ARGS = "\"<<INCLUDE_ANSIBLE_MODULE_ARGS>>\""
|
REPLACER_ARGS = "\"<<INCLUDE_ANSIBLE_MODULE_ARGS>>\""
|
||||||
REPLACER_COMPLEX = "\"<<INCLUDE_ANSIBLE_MODULE_COMPLEX_ARGS>>\""
|
REPLACER_COMPLEX = "\"<<INCLUDE_ANSIBLE_MODULE_COMPLEX_ARGS>>\""
|
||||||
|
REPLACER_WINDOWS = "# POWERSHELL_COMMON"
|
||||||
|
|
||||||
class ModuleReplacer(object):
|
class ModuleReplacer(object):
|
||||||
|
|
||||||
|
@ -54,6 +55,10 @@ class ModuleReplacer(object):
|
||||||
|
|
||||||
All modules are required to import at least basic, though there will also
|
All modules are required to import at least basic, though there will also
|
||||||
be other snippets.
|
be other snippets.
|
||||||
|
|
||||||
|
# POWERSHELL_COMMON will also map to
|
||||||
|
{{ include 'powershell.ps1' }}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ******************************************************************************
|
# ******************************************************************************
|
||||||
|
@ -97,6 +102,10 @@ class ModuleReplacer(object):
|
||||||
if REPLACER in line:
|
if REPLACER in line:
|
||||||
output.write(self.slurp(os.path.join(self.snippet_path, "basic.py")))
|
output.write(self.slurp(os.path.join(self.snippet_path, "basic.py")))
|
||||||
snippet_names.append('basic')
|
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.'):
|
elif line.startswith('from ansible.module_utils.'):
|
||||||
tokens=line.split(".")
|
tokens=line.split(".")
|
||||||
import_error = False
|
import_error = False
|
||||||
|
@ -116,8 +125,14 @@ class ModuleReplacer(object):
|
||||||
output.write(line)
|
output.write(line)
|
||||||
output.write("\n")
|
output.write("\n")
|
||||||
|
|
||||||
if len(snippet_names) > 0 and not 'basic' in snippet_names:
|
if not module_path.endswith(".ps1"):
|
||||||
raise errors.AnsibleError("missing required import in %s: from ansible.module_utils.basic import *" % module_path)
|
# 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)
|
return (output.getvalue(), module_style)
|
||||||
|
|
||||||
|
|
30
lib/ansible/module_utils/powershell.ps1
Normal file
30
lib/ansible/module_utils/powershell.ps1
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
|
||||||
|
# This particular file snippet, and this file snippet only, is BSD licensed.
|
||||||
|
# Modules you write using this snippet, which is embedded dynamically by Ansible
|
||||||
|
# still belong to the author of the module, and may assign their own license
|
||||||
|
# to the complete work.
|
||||||
|
#
|
||||||
|
# Copyright (c), Michael DeHaan <michael.dehaan@gmail.com>, 2014, and others
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
# are permitted provided that the following conditions are met:
|
||||||
|
#
|
||||||
|
# * Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
# this list of conditions and the following disclaimer in the documentation
|
||||||
|
# and/or other materials provided with the distribution.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||||
|
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue