mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Change the v2 filter plugins into a symlink to v1 as the plugins are the same for both
This commit is contained in:
parent
0e5f86cce4
commit
03e213a272
3 changed files with 72 additions and 26 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit be744ce5e78f217eb34c4d369847f1e174da9ae6
|
Subproject commit 1394920cd3e440f5806463d0c1cfbe4a4b94f423
|
|
@ -1,21 +0,0 @@
|
||||||
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# Make coding more python3-ish
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
|
@ -15,23 +15,33 @@
|
||||||
# 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/>.
|
||||||
|
|
||||||
|
import sys
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import yaml
|
|
||||||
import types
|
import types
|
||||||
import pipes
|
import pipes
|
||||||
import glob
|
import glob
|
||||||
import re
|
import re
|
||||||
import collections
|
import collections
|
||||||
|
import crypt
|
||||||
|
import hashlib
|
||||||
|
import string
|
||||||
import operator as py_operator
|
import operator as py_operator
|
||||||
from distutils.version import LooseVersion, StrictVersion
|
|
||||||
from random import SystemRandom, shuffle
|
from random import SystemRandom, shuffle
|
||||||
from jinja2.filters import environmentfilter
|
import uuid
|
||||||
|
|
||||||
from ansible.errors import *
|
import yaml
|
||||||
|
from jinja2.filters import environmentfilter
|
||||||
|
from distutils.version import LooseVersion, StrictVersion
|
||||||
|
|
||||||
|
from ansible import errors
|
||||||
from ansible.utils.hashing import md5s, checksum_s
|
from ansible.utils.hashing import md5s, checksum_s
|
||||||
|
|
||||||
|
|
||||||
|
UUID_NAMESPACE_ANSIBLE = uuid.UUID('361E6D51-FAEC-444A-9079-341386DA8E2E')
|
||||||
|
|
||||||
|
|
||||||
def to_nice_yaml(*a, **kw):
|
def to_nice_yaml(*a, **kw):
|
||||||
'''Make verbose, human readable yaml'''
|
'''Make verbose, human readable yaml'''
|
||||||
return yaml.safe_dump(*a, indent=4, allow_unicode=True, default_flow_style=False, **kw)
|
return yaml.safe_dump(*a, indent=4, allow_unicode=True, default_flow_style=False, **kw)
|
||||||
|
@ -42,6 +52,22 @@ def to_json(a, *args, **kw):
|
||||||
|
|
||||||
def to_nice_json(a, *args, **kw):
|
def to_nice_json(a, *args, **kw):
|
||||||
'''Make verbose, human readable JSON'''
|
'''Make verbose, human readable JSON'''
|
||||||
|
# python-2.6's json encoder is buggy (can't encode hostvars)
|
||||||
|
if sys.version_info < (2, 7):
|
||||||
|
try:
|
||||||
|
import simplejson
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
major = int(simplejson.__version__.split('.')[0])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if major >= 2:
|
||||||
|
return simplejson.dumps(a, indent=4, sort_keys=True, *args, **kw)
|
||||||
|
# Fallback to the to_json filter
|
||||||
|
return to_json(a, *args, **kw)
|
||||||
return json.dumps(a, indent=4, sort_keys=True, *args, **kw)
|
return json.dumps(a, indent=4, sort_keys=True, *args, **kw)
|
||||||
|
|
||||||
def failed(*a, **kw):
|
def failed(*a, **kw):
|
||||||
|
@ -243,6 +269,41 @@ def randomize_list(mylist):
|
||||||
pass
|
pass
|
||||||
return mylist
|
return mylist
|
||||||
|
|
||||||
|
def get_hash(data, hashtype='sha1'):
|
||||||
|
|
||||||
|
try: # see if hash is supported
|
||||||
|
h = hashlib.new(hashtype)
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
h.update(data)
|
||||||
|
return h.hexdigest()
|
||||||
|
|
||||||
|
def get_encrypted_password(password, hashtype='sha512', salt=None):
|
||||||
|
|
||||||
|
# TODO: find a way to construct dynamically from system
|
||||||
|
cryptmethod= {
|
||||||
|
'md5': '1',
|
||||||
|
'blowfish': '2a',
|
||||||
|
'sha256': '5',
|
||||||
|
'sha512': '6',
|
||||||
|
}
|
||||||
|
|
||||||
|
hastype = hashtype.lower()
|
||||||
|
if hashtype in cryptmethod:
|
||||||
|
if salt is None:
|
||||||
|
r = SystemRandom()
|
||||||
|
salt = ''.join([r.choice(string.ascii_letters + string.digits) for _ in range(16)])
|
||||||
|
|
||||||
|
saltstring = "$%s$%s" % (cryptmethod[hashtype],salt)
|
||||||
|
encrypted = crypt.crypt(password,saltstring)
|
||||||
|
return encrypted
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def to_uuid(string):
|
||||||
|
return str(uuid.uuid5(UUID_NAMESPACE_ANSIBLE, str(string)))
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
''' Ansible core jinja2 filters '''
|
''' Ansible core jinja2 filters '''
|
||||||
|
|
||||||
|
@ -252,6 +313,9 @@ class FilterModule(object):
|
||||||
'b64decode': base64.b64decode,
|
'b64decode': base64.b64decode,
|
||||||
'b64encode': base64.b64encode,
|
'b64encode': base64.b64encode,
|
||||||
|
|
||||||
|
# uuid
|
||||||
|
'to_uuid': to_uuid,
|
||||||
|
|
||||||
# json
|
# json
|
||||||
'to_json': to_json,
|
'to_json': to_json,
|
||||||
'to_nice_json': to_nice_json,
|
'to_nice_json': to_nice_json,
|
||||||
|
@ -295,6 +359,9 @@ class FilterModule(object):
|
||||||
'sha1': checksum_s,
|
'sha1': checksum_s,
|
||||||
# checksum of string as used by ansible for checksuming files
|
# checksum of string as used by ansible for checksuming files
|
||||||
'checksum': checksum_s,
|
'checksum': checksum_s,
|
||||||
|
# generic hashing
|
||||||
|
'password_hash': get_encrypted_password,
|
||||||
|
'hash': get_hash,
|
||||||
|
|
||||||
# file glob
|
# file glob
|
||||||
'fileglob': fileglob,
|
'fileglob': fileglob,
|
||||||
|
|
Loading…
Reference in a new issue