mirror of https://github.com/ansible/ansible.git
Merge 259a6df398
into 6aa8192131
commit
5b34c69465
@ -0,0 +1,8 @@
|
||||
deprecated_features:
|
||||
- >-
|
||||
Deprecated YAML parsing of unquoted datetime strings like ``2002-12-14``, ``2001-12-15 2:59:43.10``, ``2001-12-15T02:59:43.1Z``,
|
||||
into a datetime object. Parsing as a datetime object will change the value used when using the value,
|
||||
for example as a module option. To opt into the new behaviour before Ansible 2.21, quote the YAML value so it stays a string.
|
||||
To preserve the existing behaviour use the ``to_datetime`` filter, for example ``key: 2023-05-19T11:49:52Z`` would now be
|
||||
``key: '{{ "2023-05-19T11:49:52Z" | to_datetime("%Y-%m-%dT%H:%M:%S%z") }}'``. Jinja2 native needs to be enabled to
|
||||
preserve the datetime value outside the template.
|
@ -0,0 +1,25 @@
|
||||
- hosts: localhost
|
||||
gather_facts: false
|
||||
vars:
|
||||
plain_scalar: 2023-05-19T11:49:01Z
|
||||
tag_shorthand: !!timestamp 2023-05-19T11:49:02Z
|
||||
tag_full: !<tag:yaml.org,2002:timestamp> 2023-05-19T11:49:03Z
|
||||
quoted: '2023-05-19T11:49:01Z'
|
||||
tag_str: !!str 2023-05-19T11:49:01Z
|
||||
template_str: '{{ "2023-05-19T11:49:01Z" | string }}'
|
||||
template_to_dt: '{{ "2023-05-19T11:49:01Z" | to_datetime("%Y-%m-%dT%H:%M:%S%z") }}'
|
||||
|
||||
tasks:
|
||||
- set_fact:
|
||||
parse_result:
|
||||
plain_scalar: {v: '{{ plain_scalar | string }}', t: '{{ plain_scalar | type_debug }}'}
|
||||
tag_shorthand: {v: '{{ tag_shorthand | string }}', t: '{{ tag_shorthand | type_debug }}'}
|
||||
tag_full: {v: '{{ tag_full | string }}', t: '{{ tag_full | type_debug }}'}
|
||||
quoted: {v: '{{ quoted | string }}', t: '{{ quoted | type_debug }}'}
|
||||
tag_str: {v: '{{ tag_str | string }}', t: '{{ tag_str | type_debug }}'}
|
||||
template_str: {v: '{{ template_str | string }}', t: '{{ template_str | type_debug }}'}
|
||||
template_to_dt: {v: '{{ template_to_dt | string }}', t: '{{ template_to_dt | type_debug }}'}
|
||||
|
||||
- name: print result
|
||||
debug:
|
||||
var: parse_result
|
@ -0,0 +1,48 @@
|
||||
# Copyright: (c) 2024, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
|
||||
def parse_datetime_result(value):
|
||||
res_split = value.split("ok: [localhost] => ")[1]
|
||||
raw_result = res_split.split("PLAY RECAP")[0]
|
||||
|
||||
return json.loads(raw_result)["parse_result"]
|
||||
|
||||
|
||||
def parse_datetime_warnings(value):
|
||||
warnings = []
|
||||
buffer = []
|
||||
start_capture = False
|
||||
|
||||
for line in value.split("\n"):
|
||||
if not start_capture:
|
||||
if line.startswith("[DEPRECATION WARNING]: "):
|
||||
start_capture = True
|
||||
line = line[23:]
|
||||
else:
|
||||
continue
|
||||
|
||||
elif line.startswith("[DEPRECATION WARNING]: "):
|
||||
warnings.append("".join(buffer).strip())
|
||||
buffer = []
|
||||
line = line[23:]
|
||||
|
||||
buffer.append(line)
|
||||
|
||||
if buffer:
|
||||
warnings.append("".join(buffer).strip())
|
||||
|
||||
return warnings
|
||||
|
||||
|
||||
class FilterModule:
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'parse_datetime_result': parse_datetime_result,
|
||||
'parse_datetime_warnings': parse_datetime_warnings,
|
||||
}
|
Loading…
Reference in New Issue