Calculation of certificate expiration date won't work with some locales · Issue #124 · NETWAYS/ansible-collection-elasticstack · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running the collection a second time over a test system I get an error when it tries to calculate the expiration date of certificates.
TASK [netways.elasticstack.elasticsearch : Set the ca expiration date in days] **************************************************************************************************************************************************************
fatal: [elastic801]: FAILED! => {"msg": "the field 'args' has an invalid value ({'elastic_ca_expiration_days': \"{{ ((ca_expiration_date.stdout | to_datetime('%b %d %H:%M:%S %Y %Z')) - (ansible_date_time.date | to_datetime('%Y-%m-%d'))).days }}\"}), and could not be converted to an dict.The error was: time data 'Mar 16 15:55:01 2026 GMT' does not match format '%b %d %H:%M:%S %Y %Z'\n\nThe error appears to be in '/home/widhalmt/.ansible/collections/ansible_collections/netways/elasticstack/roles/elasticsearch/tasks/elasticsearch-security.yml': line 34, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Set the ca expiration date in days\n ^ here\n"}
The to_datetime calculation is correct and the string does match the pattern. Only problem is that %b refers to "Month as locale’s abbreviated name." . So this can or can not work depending on locales on all involved machines.
[widhalmt@thor elastictest]$ ansible localhost -m debug -a='msg={{ "Mar 16 15:55:01 2026" | to_datetime("%b %d %H:%M:%S %Y") }}'
localhost | FAILED! => {
"msg": "the field 'args' has an invalid value ({'msg': '{{ \"Mar 16 15:55:01 2026\" | to_datetime(\"%b %d %H:%M:%S %Y\") }}'}), and could not be converted to an dict.The error was: time data 'Mar 16 15:55:01 2026' does not match format '%b %d %H:%M:%S %Y'. time data 'Mar 16 15:55:01 2026' does not match format '%b %d %H:%M:%S %Y'"
}
[widhalmt@thor elastictest]$ ansible localhost -m debug -a='msg={{ "Mär 16 15:55:01 2026" | to_datetime("%b %d %H:%M:%S %Y") }}'
localhost | SUCCESS => {
"msg": "2026-03-16 15:55:01"
}
So when I change Mar to Mär matching the locale, it works. But we need a way to fix it to the locale openssl is using when showing dates.
The text was updated successfully, but these errors were encountered:
Setting locale at the task level doesn't work, either.
- name: Set the ca expiration date in days
set_fact:
elastic_ca_expiration_days: "{{ ((ca_expiration_date.stdout | to_datetime('%b %d %H:%M:%S %Y %Z')) - (ansible_date_time.date | to_datetime('%Y-%m-%d'))).days }}"
when: inventory_hostname == elasticsearch_ca and ca_expiration_date.skipped is not defined
environment:
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
LC_ALL: en_US.UTF-8
Uh oh!
There was an error while loading. Please reload this page.
When running the collection a second time over a test system I get an error when it tries to calculate the expiration date of certificates.
The
to_datetime
calculation is correct and the string does match the pattern. Only problem is that%b
refers to "Month as locale’s abbreviated name." . So this can or can not work depending on locales on all involved machines.So when I change
Mar
toMär
matching the locale, it works. But we need a way to fix it to the localeopenssl
is using when showing dates.The text was updated successfully, but these errors were encountered: