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
4f32a615
Commit
4f32a615
authored
Aug 19, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10957 from feanil/feanil/retain_nonetypes
Don't convert nulls to strings.
parents
0eba8191
892e2305
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
2 deletions
+20
-2
CHANGELOG.md
+7
-0
lib/ansible/constants.py
+5
-1
lib/ansible/template/__init__.py
+3
-0
test/integration/roles/test_template/files/foo.txt
+1
-0
test/integration/roles/test_template/vars/main.yml
+2
-0
v1/ansible/utils/template.py
+2
-1
No files found.
CHANGELOG.md
View file @
4f32a615
...
...
@@ -18,6 +18,13 @@ Major Changes:
If you need the old behaviour, quote the value and it will get passed around as a string
*
added meta: refresh_inventory to force rereading the inventory in a play
*
vars are now settable at play, block, role and task level
*
template code now retains types for bools, and Numbers instead of turning them into strings
If you need the old behaviour, quote the value and it will get passed around as a string. In the
case of nulls, the output used to be an empty string.
*
Empty variables and variables set to null in yaml will no longer be converted to empty strings.
They will retain the value of
`None`
. To go back to the old behaviour, you can override
the
`null_representation`
setting to an empty string in your config file or by setting the
`ANSIBLE_NULL_REPRESENTATION`
environment variable.
Deprecated Modules (new ones in parens):
*
ec2_ami_search (ec2_ami_find)
...
...
lib/ansible/constants.py
View file @
4f32a615
...
...
@@ -40,7 +40,7 @@ def mk_boolean(value):
else
:
return
False
def
get_config
(
p
,
section
,
key
,
env_var
,
default
,
boolean
=
False
,
integer
=
False
,
floating
=
False
,
islist
=
False
):
def
get_config
(
p
,
section
,
key
,
env_var
,
default
,
boolean
=
False
,
integer
=
False
,
floating
=
False
,
islist
=
False
,
isnone
=
False
):
''' return a configuration variable with casting '''
value
=
_get_config
(
p
,
section
,
key
,
env_var
,
default
)
if
boolean
:
...
...
@@ -53,6 +53,9 @@ def get_config(p, section, key, env_var, default, boolean=False, integer=False,
elif
islist
:
if
isinstance
(
value
,
string_types
):
value
=
[
x
.
strip
()
for
x
in
value
.
split
(
','
)]
elif
isnone
:
if
value
==
"None"
:
value
=
None
elif
isinstance
(
value
,
string_types
):
value
=
unquote
(
value
)
return
value
...
...
@@ -205,6 +208,7 @@ DEFAULT_LOAD_CALLBACK_PLUGINS = get_config(p, DEFAULTS, 'bin_ansible_callbacks'
DEFAULT_CALLBACK_WHITELIST
=
get_config
(
p
,
DEFAULTS
,
'callback_whitelist'
,
'ANSIBLE_CALLBACK_WHITELIST'
,
[],
islist
=
True
)
RETRY_FILES_ENABLED
=
get_config
(
p
,
DEFAULTS
,
'retry_files_enabled'
,
'ANSIBLE_RETRY_FILES_ENABLED'
,
True
,
boolean
=
True
)
RETRY_FILES_SAVE_PATH
=
get_config
(
p
,
DEFAULTS
,
'retry_files_save_path'
,
'ANSIBLE_RETRY_FILES_SAVE_PATH'
,
'~/'
)
DEFAULT_NULL_REPRESENTATION
=
get_config
(
p
,
DEFAULTS
,
'null_representation'
,
'ANSIBLE_NULL_REPRESENTATION'
,
None
,
isnone
=
True
)
# CONNECTION RELATED
ANSIBLE_SSH_ARGS
=
get_config
(
p
,
'ssh_connection'
,
'ssh_args'
,
'ANSIBLE_SSH_ARGS'
,
None
)
...
...
lib/ansible/template/__init__.py
View file @
4f32a615
...
...
@@ -37,6 +37,7 @@ from ansible.template.vars import AnsibleJ2Vars
from
ansible.utils.debug
import
debug
from
numbers
import
Number
from
types
import
NoneType
__all__
=
[
'Templar'
]
...
...
@@ -187,6 +188,8 @@ class Templar:
resolved_val
=
self
.
_available_variables
[
var_name
]
if
isinstance
(
resolved_val
,
NON_TEMPLATED_TYPES
):
return
resolved_val
elif
isinstance
(
resolved_val
,
NoneType
):
return
C
.
DEFAULT_NULL_REPRESENTATION
result
=
self
.
_do_template
(
variable
,
preserve_trailing_newlines
=
preserve_trailing_newlines
,
fail_on_undefined
=
fail_on_undefined
,
overrides
=
overrides
)
...
...
test/integration/roles/test_template/files/foo.txt
View file @
4f32a615
...
...
@@ -3,6 +3,7 @@ templated_var_loaded
{
"bool": true,
"multi_part": "1Foo",
"null_type": null,
"number": 5,
"string_num": "5"
}
test/integration/roles/test_template/vars/main.yml
View file @
4f32a615
...
...
@@ -5,10 +5,12 @@ string_num: "5"
bool_var
:
true
part_1
:
1
part_2
:
"
Foo"
null_type
:
!!null
templated_dict
:
number
:
"
{{
number_var
}}"
string_num
:
"
{{
string_num
}}"
null_type
:
"
{{
null_type
}}"
bool
:
"
{{
bool_var
}}"
multi_part
:
"
{{
part_1
}}{{
part_2
}}"
v1/ansible/utils/template.py
View file @
4f32a615
...
...
@@ -32,6 +32,7 @@ import pwd
import
ast
import
traceback
from
numbers
import
Number
from
types
import
NoneType
from
ansible.utils.string_functions
import
count_newlines_from_end
from
ansible.utils
import
to_bytes
,
to_unicode
...
...
@@ -343,7 +344,7 @@ def template_from_string(basedir, data, vars, fail_on_undefined=False):
var_name
=
only_one
.
group
(
1
)
if
var_name
in
vars
:
resolved_val
=
vars
[
var_name
]
if
isinstance
(
resolved_val
,
(
bool
,
Number
)):
if
isinstance
(
resolved_val
,
(
bool
,
Number
,
NoneType
)):
return
resolved_val
def
my_finalize
(
thing
):
...
...
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