Random parameters but keeping idempotent

56 views
Skip to first unread message

iprok

unread,
Dec 14, 2014, 2:14:04 PM12/14/14
to ansible...@googlegroups.com
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.

Dick Davies

unread,
Dec 15, 2014, 6:00:25 AM12/15/14
to ansible list
How about hashing their hostnames, or using something else unique but constant
about them (last octet of their IP, maybe)?
> --
> 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-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5e307694-510f-4ece-b877-8788ecf153a8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Dec 15, 2014, 9:23:30 AM12/15/14
to ansible...@googlegroups.com
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.

--
Brian Coca

iprok

unread,
Dec 15, 2014, 9:26:00 AM12/15/14
to ansible...@googlegroups.com


понедельник, 15 декабря 2014 г., 17:23:30 UTC+3 пользователь Brian Coca написал:
I've used the random filter to conditionally create either host_vars
with the value (if file exists it doesn't regenerate)

Sounds interesting. How have you done this?

Brian Coca

unread,
Dec 15, 2014, 10:35:25 AM12/15/14
to ansible...@googlegroups.com
example (i prefer template but this makes it a 1 liner):

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



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages