Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
03e213a2
Commit
03e213a2
authored
Feb 02, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change the v2 filter plugins into a symlink to v1 as the plugins are the same for both
parent
0e5f86cc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
25 deletions
+71
-25
v2/ansible/modules/core
+1
-1
v2/ansible/plugins/filter/__init__.py
+0
-21
v2/ansible/plugins/filter/core.py
+70
-3
No files found.
core
@
1394920c
Subproject commit
be744ce5e78f217eb34c4d369847f1e174da9ae6
Subproject commit
1394920cd3e440f5806463d0c1cfbe4a4b94f423
v2/ansible/plugins/filter/__init__.py
View file @
03e213a2
# (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
v2/ansible/plugins/filter/core.py
View file @
03e213a2
...
...
@@ -15,23 +15,33 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
sys
import
base64
import
json
import
os.path
import
yaml
import
types
import
pipes
import
glob
import
re
import
collections
import
crypt
import
hashlib
import
string
import
operator
as
py_operator
from
distutils.version
import
LooseVersion
,
StrictVersion
from
random
import
SystemRandom
,
shuffle
import
uuid
import
yaml
from
jinja2.filters
import
environmentfilter
from
distutils.version
import
LooseVersion
,
StrictVersion
from
ansible
.errors
import
*
from
ansible
import
errors
from
ansible.utils.hashing
import
md5s
,
checksum_s
UUID_NAMESPACE_ANSIBLE
=
uuid
.
UUID
(
'361E6D51-FAEC-444A-9079-341386DA8E2E'
)
def
to_nice_yaml
(
*
a
,
**
kw
):
'''Make verbose, human readable yaml'''
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
):
'''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
)
def
failed
(
*
a
,
**
kw
):
...
...
@@ -243,6 +269,41 @@ def randomize_list(mylist):
pass
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
):
''' Ansible core jinja2 filters '''
...
...
@@ -252,6 +313,9 @@ class FilterModule(object):
'b64decode'
:
base64
.
b64decode
,
'b64encode'
:
base64
.
b64encode
,
# uuid
'to_uuid'
:
to_uuid
,
# json
'to_json'
:
to_json
,
'to_nice_json'
:
to_nice_json
,
...
...
@@ -295,6 +359,9 @@ class FilterModule(object):
'sha1'
:
checksum_s
,
# checksum of string as used by ansible for checksuming files
'checksum'
:
checksum_s
,
# generic hashing
'password_hash'
:
get_encrypted_password
,
'hash'
:
get_hash
,
# file glob
'fileglob'
:
fileglob
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment