Thanks David

I have tried similar to the above but get a templating error:

{
  "msg": "Unexpected templating type error occurred on ({{ ( 
(ansible_date_time.date - date_earlier).total_seconds() / 3600 ) | int }}): 
unsupported operand type(s) for -: 'AnsibleUnsafeText' and 'dict'",
  "_ansible_no_log": false
}

Here is my code:

---
- hosts: localhost
  gather_facts: true
  tasks:
  

  - name: Get AMI info
    amazon.aws.ec2_ami_info:
      aws_access_key: "{{ lookup('env','AWS_ACCESS_KEY_ID') }}"
      aws_secret_key: "{{ lookup('env','AWS_SECRET_ACCESS_KEY') }}"
      region: eu-west-1
      filters:
        "tag:Backup_Policy": 1
    register: date_earlier

  - name: Compare AMI date
    debug:
      msg: "{{ ( (ansible_date_time.date - date_earlier).total_seconds() / 
3600 ) | int }}"

Any help would be appreciated
On Saturday, 11 September 2021 at 19:56:24 UTC+1 david...@mycit.ie wrote:

>
> https://stackoverflow.com/questions/48101921/ansible-compare-difference-between-two-dates-for-the-last-hour
>
> On Saturday, September 11, 2021 at 5:09:48 PM UTC+1 
> antony.a...@googlemail.com wrote:
>
>> Hi, would really appreciate some help if possible.
>>
>> I am using ec2_ami_info to capture the creation date.
>>
>> I register the output as ami_creation_date.
>>
>> Output is: 2021-09-09
>>
>> I would like to delete the AMI if it is 2 days older than now.
>>
>> I've tried some code I've used in the past but getting templating errors 
>> etc.
>>
>> Using the latest release of AWX.
>>
>> Would really appreciate it if someone can help :)
>>
>> thank you!
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/82b680f4-71e7-4f2b-86ca-26cf297e0ce6n%40googlegroups.com.

Reply via email to