Compare commits
2 Commits
744dc312ab
...
1228dc1365
Author | SHA1 | Date |
---|---|---|
Benjamin Bohard | 1228dc1365 | |
Benjamin Bohard | ee1dc26530 |
|
@ -86,19 +86,17 @@ def run_module():
|
||||||
try:
|
try:
|
||||||
from creole.eoleversion import EOLE_RELEASE
|
from creole.eoleversion import EOLE_RELEASE
|
||||||
from creole.client import CreoleClient
|
from creole.client import CreoleClient
|
||||||
module_eole = CreoleClient().get_creole('eole_module')
|
|
||||||
|
|
||||||
result['ansible_facts'] = {
|
result['ansible_facts'] = {
|
||||||
'is_eole': True,
|
'is_eole': True,
|
||||||
'module_eole': module_eole,
|
|
||||||
'release_eole': EOLE_RELEASE,
|
'release_eole': EOLE_RELEASE,
|
||||||
}
|
}
|
||||||
except:
|
except:
|
||||||
result['ansible_facts'] = {'is_eole': False}
|
result['ansible_facts'] = {'is_eole': False}
|
||||||
|
|
||||||
|
module.exit_json(**result)
|
||||||
|
|
||||||
# in the event of a successful module execution, you will want to
|
# in the event of a successful module execution, you will want to
|
||||||
# simple AnsibleModule.exit_json(), passing the key/value results
|
# simple AnsibleModule.exit_json(), passing the key/value results
|
||||||
module.exit_json(**result)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# Copyright: (c) 2021, Cadoles <contact@cadoles.com>
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
DOCUMENTATION = r'''
|
||||||
|
---
|
||||||
|
module: eole_module_facts
|
||||||
|
|
||||||
|
short_description: Gathers facts about EOLE modules
|
||||||
|
|
||||||
|
version_added: "1.0.0"
|
||||||
|
|
||||||
|
description: Determines which EOLE module targeted server is.
|
||||||
|
|
||||||
|
author:
|
||||||
|
- Benjamin Bohard
|
||||||
|
'''
|
||||||
|
EXAMPLES = r'''
|
||||||
|
- name: Return ansible_facts
|
||||||
|
cadoles.eole.eole_module_facts:
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''
|
||||||
|
# These are examples of possible return values, and in general should use other names for return values.
|
||||||
|
ansible_facts:
|
||||||
|
description: Facts to add to ansible_facts.
|
||||||
|
returned: always
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
module_eole:
|
||||||
|
description: eole module facts about operating system.
|
||||||
|
type: str
|
||||||
|
returned: when operating system eole module fact is present
|
||||||
|
sample: 'eolebase'
|
||||||
|
'''
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
|
def run_module():
|
||||||
|
# define available arguments/parameters a user can pass to the module
|
||||||
|
module_args = dict()
|
||||||
|
|
||||||
|
# seed the result dict in the object
|
||||||
|
# we primarily care about changed and state
|
||||||
|
# changed is if this module effectively modified the target
|
||||||
|
# state will include any data that you want your module to pass back
|
||||||
|
# for consumption, for example, in a subsequent task
|
||||||
|
result = dict(
|
||||||
|
changed=False,
|
||||||
|
ansible_facts=dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
# the AnsibleModule object will be our abstraction working with Ansible
|
||||||
|
# this includes instantiation, a couple of common attr would be the
|
||||||
|
# args/params passed to the execution, as well as if the module
|
||||||
|
# supports check mode
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec=module_args,
|
||||||
|
supports_check_mode=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# if the user is working with this module in only check mode we do not
|
||||||
|
# want to make any changes to the environment, just return the current
|
||||||
|
# state with no modifications
|
||||||
|
if module.check_mode:
|
||||||
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
# manipulate or modify the state as needed (this is going to be the
|
||||||
|
# part where your module will do what it needs to do)
|
||||||
|
from creole.eoleversion import EOLE_RELEASE
|
||||||
|
from creole.client import CreoleClient
|
||||||
|
|
||||||
|
module_eole = CreoleClient().get_creole('eole_module')
|
||||||
|
|
||||||
|
result['ansible_facts'] = {
|
||||||
|
'module_eole': module_eole,
|
||||||
|
}
|
||||||
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
# in the event of a successful module execution, you will want to
|
||||||
|
# simple AnsibleModule.exit_json(), passing the key/value results
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
run_module()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -68,6 +68,18 @@ import re
|
||||||
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
||||||
|
|
||||||
|
|
||||||
|
def yml_params_to_unicode(param):
|
||||||
|
def convert_param(param):
|
||||||
|
if isinstance(param, str):
|
||||||
|
return param.decode('utf-8')
|
||||||
|
if isinstance(param, list):
|
||||||
|
return [convert_param(p) for p in param]
|
||||||
|
if isinstance(param, dict):
|
||||||
|
return {convert_param(key): convert_param(value) for key,value in param.items()}
|
||||||
|
return param
|
||||||
|
return convert_param(param)
|
||||||
|
|
||||||
|
|
||||||
class ExpectationCollection:
|
class ExpectationCollection:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.expectations_lookup = {}
|
self.expectations_lookup = {}
|
||||||
|
@ -160,6 +172,8 @@ class Expectation:
|
||||||
return False
|
return False
|
||||||
context.reverse()
|
context.reverse()
|
||||||
for index, c in enumerate(self.context[len(self.context)-2::-1]):
|
for index, c in enumerate(self.context[len(self.context)-2::-1]):
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
c = c.decode('utf-8')
|
||||||
if c != ansi_escape.sub('', context[index]):
|
if c != ansi_escape.sub('', context[index]):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -289,6 +303,7 @@ def run_module():
|
||||||
changed=False,
|
changed=False,
|
||||||
module='',
|
module='',
|
||||||
msg='',
|
msg='',
|
||||||
|
debug='',
|
||||||
)
|
)
|
||||||
|
|
||||||
# the AnsibleModule object will be our abstraction working with Ansible
|
# the AnsibleModule object will be our abstraction working with Ansible
|
||||||
|
@ -354,7 +369,7 @@ def run_module():
|
||||||
result['msg'] += "Module {} instanciated".format(result['module'])
|
result['msg'] += "Module {} instanciated".format(result['module'])
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
result['msg'] += err
|
result['msg'] += str(err)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
module.fail_json(**result)
|
module.fail_json(**result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue