Add creoleset to utilities

This commit is contained in:
Benjamin Bohard 2021-06-21 15:51:07 +02:00
parent 06f72297ca
commit a0adff89a8
4 changed files with 201 additions and 0 deletions

3
cadoles/eole/README.md Normal file
View File

@ -0,0 +1,3 @@
# Ansible Collection - cadoles.eole
Documentation for the collection.

57
cadoles/eole/galaxy.yml Normal file
View File

@ -0,0 +1,57 @@
### REQUIRED
# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with
# underscores or numbers and cannot contain consecutive underscores
namespace: cadoles
# The name of the collection. Has the same character restrictions as 'namespace'
name: eole
# The version of the collection. Must be compatible with semantic versioning
version: 1.0.0
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url)
# @nicks:irc/im.site#channel'
authors:
- Cadoles <contact@cadoles.com>
### OPTIONAL but strongly recommended
# A short summary description of the collection
description: utilities to manage EOLE servers
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
license:
- GPL-2.0-or-later
# The path to the license file for the collection. This path is relative to the root of the collection. This key is
# mutually exclusive with 'license'
license_file: 'LICENSE'
# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
# requirements as 'namespace' and 'name'
tags: []
# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
# collection label 'namespace.name'. The value is a version range
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
# range specifiers can be set and are separated by ','
dependencies: {}
# The URL of the originating SCM repository
repository: https://forge.cadoles.com/bbohard/eole-galaxy
# The URL to any online docs
documentation: http://forge.cadoles.com/bbohard/eole-galaxy/wiki
# The URL to the homepage of the collection/project
homepage: https://forge.cadoles.com/bbohard/eole-galaxy
# The URL to the collection issue tracker
issues: https://forge.cadoles.com/bbohard/eole-galaxy

View File

@ -0,0 +1,31 @@
# Collections Plugins Directory
This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that
is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that
would contain module utils and modules respectively.
Here is an example directory of the majority of plugins currently supported by Ansible:
```
└── plugins
├── action
├── become
├── cache
├── callback
├── cliconf
├── connection
├── filter
├── httpapi
├── inventory
├── lookup
├── module_utils
├── modules
├── netconf
├── shell
├── strategy
├── terminal
├── test
└── vars
```
A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible/2.9/plugins/plugins.html).

View File

@ -0,0 +1,110 @@
#!/usr/bin/python
# Copyright: (c) 2018, Terry Jones <terry.jones@example.org>
# 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: CreoleSet
short_description: This module aims to set variables on EOLE modules
version_added: "1.0.0"
description: This module aims to set variables on EOLE modules orderly and atomicly.
options:
variables:
description: Name of the variable to change.
required: true
type: list
author:
- Cadoles
'''
EXAMPLES = r'''
# Pass in a message
- variables:
- name: simple_variable
value: 'oui'
- name: list_variable
value:
- item1
- item2
- name: master_variable
value:
- item1
- item2
- name: slave_variable
value:
- item1
- item2
'''
RETURN = r'''
# These are examples of possible return values, and in general should use other names for return values.
diff:
description: variable modifications status.
type: list
returned: always
sample: ['activer_ajout_hosts: non => oui']
'''
from ansible.module_utils.basic import AnsibleModule
from creole.loader import creole_loader, config_save_values
def run_module():
# define available arguments/parameters a user can pass to the module
module_args = dict(
variables=dict(type='list', required=True),
)
# 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,
diff=[],
message=''
)
# 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
c = creole_loader(rw=True)
diff = []
for variable in module.params['variables']:
value = variable['value']
var_path = c.find_first(byname=variable['name'], type_='path')
old_value = c.getattr(var_path)
if old_value != value:
diff.append('{}: {} => {}'.format(variable, old_value, value))
c.setattr(var_path, value)
result['diff'] = diff
if not module.check_mode:
config_save_values(c, 'creole')
#if not module.check_mode:
# config_save_values(c, 'creole')
module.exit_json(**result)
def main():
run_module()
if __name__ == '__main__':
main()