# ansible date and time variable

**URL:** <https://forum.ansible.com/t/ansible-date-and-time-variable/32961>\
**Category:** Ansible Project\
**Created:** [May 18, 2020, 3:29pm UTC](https://forum.ansible.com/t/ansible-date-and-time-variable/32961 "2020-05-18T15:29:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Om\_Prasad\_Reddy\_Sura](https://avatars.discourse-cdn.com/v4/letter/o/6f9a4e/32.png) [@Om\_Prasad\_Reddy\_Sura](https://forum.ansible.com/u/Om_Prasad_Reddy_Sura)\
**Post date:** [May 18, 2020, 3:29pm UTC](https://forum.ansible.com/t/ansible-date-and-time-variable/32961/1 "2020-05-18T15:29:44Z")

</div>

Hi Everyone,

I have an ansible playbook which will be used to take AMI snapshot of EC2 instance **every month** in a year.

Now i got a new requirement that snapshot should not be taken for every month and it should for 3 months once. I checked **ansible\_date\_time** but did not see the logic to take every 3 months. It has just day, month and yearly like **ansible\_date\_time.month.**

**here is my playbook (variable calls from template).** Is there any way to take snapshot for every 3 months. It would be grateful if anyone could answer.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 18, 2020, 4:06pm UTC](https://forum.ansible.com/t/ansible-date-and-time-variable/32961/2 "2020-05-18T16:06:02Z")

</div>

> Hi Everyone,
> 
> I have an ansible playbook which will be used to take AMI snapshot of EC2 instance every month in a year.

"Will be used" implies some existing mechanism to take snapshots.  
The playbook you mentioned below doesn't seem to have any scheduling.  
So what is the mechanism? Cloudwatch? Cron? Manual action?

> Now i got a new requirement that snapshot should not be taken for every month and it should for 3 months once. I checked ansible\_date\_time but did not see the logic to take every 3 months. It has just day, month and yearly like ansible\_date\_time.month.

Can you please explain a bit better what you mean by "it should for 3  
months once"?

> here is my playbook (variable calls from template). Is there any way to take snapshot for every 3 months. It would be grateful if anyone could answer.
> 
> ------------------------
> 
> - hosts: localhost  
> &nbsp;&nbsp;connection: local
> 
> &nbsp;&nbsp;vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;- ami\_instance\_id: null  
> &nbsp;&nbsp;&nbsp;&nbsp;- ami\_date: "{{ ansible\_date\_time.month }}{{ ansible\_date\_time.year }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;- ami\_name: null  
> &nbsp;&nbsp;&nbsp;&nbsp;- ami\_service: null  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;- name: create AMI  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ec2\_ami:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance\_id: "{{ ami\_instance\_id }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wait: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: "{{ ami\_name }}\_{{ ami\_date }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;region: us-east-1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tags:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: "{{ ami\_name }}\_{{ ami\_date }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Service: "{{ ami\_service }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: instance
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- debug: var=instance

Did you mean to post some results here?

---

<div class="post-metadata">

**Author:** ![Om\_Prasad\_Reddy\_Sura](https://avatars.discourse-cdn.com/v4/letter/o/6f9a4e/32.png) [@Om\_Prasad\_Reddy\_Sura](https://forum.ansible.com/u/Om_Prasad_Reddy_Sura)\
**Post date:** [May 18, 2020, 4:10pm UTC](https://forum.ansible.com/t/ansible-date-and-time-variable/32961/3 "2020-05-18T16:10:55Z")

</div>

Thanks for your reply.

it was actually scheduled with crontab on Ansible Tower. I found that there is an option to change the interval every 3 months.

Thanks,  
Om
