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
54c25a10
Commit
54c25a10
authored
Jan 22, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10029 from gaqzi/devel
Add filter to turn a string into a UUID
parents
7e538d54
65e4f2b2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
0 deletions
+18
-0
docsite/rst/playbooks_variables.rst
+4
-0
lib/ansible/runner/filter_plugins/core.py
+9
-0
test/units/TestFilters.py
+5
-0
No files found.
docsite/rst/playbooks_variables.rst
View file @
54c25a10
...
@@ -409,6 +409,10 @@ To work with Base64 encoded strings::
...
@@ -409,6 +409,10 @@ To work with Base64 encoded strings::
{{ encoded | b64decode }}
{{ encoded | b64decode }}
{{ decoded | b64encode }}
{{ decoded | b64encode }}
To create a UUID from a string (new in version 1.9)::
{{ hostname | to_uuid }}
To cast values as certain types, such as when you input a string as "True" from a vars_prompt and the system
To cast values as certain types, such as when you input a string as "True" from a vars_prompt and the system
doesn't know it is a boolean value::
doesn't know it is a boolean value::
...
...
lib/ansible/runner/filter_plugins/core.py
View file @
54c25a10
...
@@ -29,6 +29,7 @@ import hashlib
...
@@ -29,6 +29,7 @@ import hashlib
import
string
import
string
import
operator
as
py_operator
import
operator
as
py_operator
from
random
import
SystemRandom
,
shuffle
from
random
import
SystemRandom
,
shuffle
import
uuid
import
yaml
import
yaml
from
jinja2.filters
import
environmentfilter
from
jinja2.filters
import
environmentfilter
...
@@ -38,6 +39,9 @@ from ansible import errors
...
@@ -38,6 +39,9 @@ from ansible import errors
from
ansible.utils
import
md5s
,
checksum_s
from
ansible.utils
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
)
...
@@ -297,6 +301,8 @@ def get_encrypted_password(password, hashtype='sha512', salt=None):
...
@@ -297,6 +301,8 @@ def get_encrypted_password(password, hashtype='sha512', salt=None):
return
None
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 '''
...
@@ -307,6 +313,9 @@ class FilterModule(object):
...
@@ -307,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
,
...
...
test/units/TestFilters.py
View file @
54c25a10
...
@@ -131,6 +131,11 @@ class TestFilters(unittest.TestCase):
...
@@ -131,6 +131,11 @@ class TestFilters(unittest.TestCase):
'a
\\
1'
)
'a
\\
1'
)
assert
a
==
'ansible'
assert
a
==
'ansible'
def
test_to_uuid
(
self
):
a
=
ansible
.
runner
.
filter_plugins
.
core
.
to_uuid
(
'example.com'
)
assert
a
==
'ae780c3a-a3ab-53c2-bfb4-098da300b3fe'
#def test_filters(self):
#def test_filters(self):
# this test is pretty low level using a playbook, hence I am disabling it for now -- MPD.
# this test is pretty low level using a playbook, hence I am disabling it for now -- MPD.
...
...
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