# Random parameters but keeping idempotent

**URL:** <https://forum.ansible.com/t/random-parameters-but-keeping-idempotent/17049>\
**Category:** Ansible Project\
**Created:** [December 14, 2014, 7:14pm UTC](https://forum.ansible.com/t/random-parameters-but-keeping-idempotent/17049 "2014-12-14T19:14:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iprok](https://avatars.discourse-cdn.com/v4/letter/i/dfb087/32.png) [@iprok](https://forum.ansible.com/u/iprok)\
**Post date:** [December 14, 2014, 7:14pm UTC](https://forum.ansible.com/t/random-parameters-but-keeping-idempotent/17049/1 "2014-12-14T19:14:04Z")

</div>

Hello!

I want to add back up task of my databases to cron. I don’t want them to start at the same time. And I have too much hosts to initialize each of them using variables. But if I use random filter it becomes unidempotent. Is it any way how to do what I want keeping idempotency?

Thank you.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [December 15, 2014, 11:00am UTC](https://forum.ansible.com/t/random-parameters-but-keeping-idempotent/17049/2 "2014-12-15T11:00:20Z")

</div>

How about hashing their hostnames, or using something else unique but constant  
about them (last octet of their IP, maybe)?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 15, 2014, 2:23pm UTC](https://forum.ansible.com/t/random-parameters-but-keeping-idempotent/17049/3 "2014-12-15T14:23:27Z")

</div>

I've used the random filter to conditionally create either host\_vars  
with the value (if file exists it doesn't regenerate), optionally you  
could create a file on the target in /etc/ansible/facts.d/

Another option would be to create something similar to the password  
lookup, a db backed random lookup.

---

<div class="post-metadata">

**Author:** ![iprok](https://avatars.discourse-cdn.com/v4/letter/i/dfb087/32.png) [@iprok](https://forum.ansible.com/u/iprok)\
**Post date:** [December 15, 2014, 2:26pm UTC](https://forum.ansible.com/t/random-parameters-but-keeping-idempotent/17049/4 "2014-12-15T14:26:00Z")

</div>

Sounds interesting. How have you done this?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 15, 2014, 3:35pm UTC](https://forum.ansible.com/t/random-parameters-but-keeping-idempotent/17049/5 "2014-12-15T15:35:20Z")

</div>

example (i prefer template but this makes it a 1 liner):

- copy: content="[defaults]\ntime={{60|random}}"  
dest=/etc/facts.d/mycronscript.facts  
&nbsp;&nbsp;when: ansible\_local is not defined or 'mycronscript' in  
ansible\_local or 'time' not in ansible\_local.mycronscripts
