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

On Sunday, 12 September 2021 at 09:18:35 UTC+1 Tony wrote:

> Sorry, that was out of date code, see below for latest
>
> ---
> - hosts: localhost
>   gather_facts: true
>   tasks:
>   
>   - name: Date
>     debug:
>       msg: "{{ ansible_date_time.date }}"
>     register: date_later
>
>   - 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: ec2_ami_info
>
>   - name: AMI Date
>     debug:
>        msg: "{{ ec2_ami_info.images.0.creation_date[:10] }}"
>     register: date_earlier
>
>   - name: test
>     debug:
>       msg: "{{ ( (date_later - date_earlier).total_seconds() / 3600 ) | 
> int }}"
>
>
>
> On Sunday, 12 September 2021 at 08:50:48 UTC+1 Tony wrote:
>
>> 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/9850a027-9f6e-464e-91fe-ce1e19210082n%40googlegroups.com.

Reply via email to