Due to security constraint, i can’t post entire output.
Below is for launchtime…let me know if you are looking for specific details
“launch_time”: “2024-06-01T06:47:48+00:00”,
“maintenance_options”: {
“auto_recovery”: “default”
doesn’t seem right to me. You’re taking an integer number of seconds, and comparing it the a string that looks like %Y-%m-%dT%H:%M:%S%z. That isn’t going to work. You’ll need to convert the calculated time in seconds into the same format as the launch_time attribute, like this:
with the caveat that I was not able to get the time zone to play nicely with that of the launch_time attribute, which is UTC. I’m not sure of the correct solution to that issue, but I was about to consider subtracting 4 hours worth of seconds from the difference (my local time being -04:00 relative to UTC).
Thanks a lot for your help. I tried as per your suggestion , But still getting same error
Below is the code modified line as per your inputs. But no luck
name: Ensure uptime_threshold_days is an integer
set_fact:
uptime_threshold_seconds: “{{ (uptime_threshold_days | int) * 86400 }}”
name: Print current time
debug:
msg:
currentime: “{{current_time_seconds}}”
No, that’s a much different error: “unsupported operand type(s) for -: ‘AnsibleUnsafeText’ and ‘str’”.
At least one of the operands is of type AnsibleUnsafeText. If the problem text is the output of the strftime() function, then you can explicitly re-cast it as str:
strftime() | str
Although, if that’s the problem, then one or both of current_time_seconds and uptime_threshold_seconds must be one of Ansible’s “Unsafe” types, too.
You can see the type of various variables by using the type_debug filter in a debug step:
- name: Show var types
ansible.builtin.debug:
msg:
- "current_time_seconds is a {{ current_time_seconds | type_debug }}."
- "uptime_threshold_seconds is a {{ uptime_threshold_seconds | type_debug }}."
If the problem datum is in your ec2_info.instances, um, I don’t know how you’d fix that.
In general, if you’re trying to use a datum in a Jinja2 expression, and it’s of one of Ansible’s “Unsafe” types, you have to explicitly cast it wherever you use it.
By the way, you can make your posts to this Forum much easier to read by enclosing your code blocks in “tripple-ticks”, possibly with a type hint, like this:
```yaml
- name: Show var types
ansible.builtin.debug:
msg:
- "current_time_seconds is a {{ current_time_seconds | type_debug }}."
- "uptime_threshold_seconds is a {{ uptime_threshold_seconds | type_debug }}."
```
Now you know. You can be a good citizen and help “future you” and others by editing your prior posts to include the opening and closing “tripple-ticks” before and after your code blocks. Note: they should be on lines all by themselves.