A better "run once" mechanism?

119 views
Skip to first unread message

Jesse Keating

unread,
Mar 11, 2014, 6:39:19 PM3/11/14
to ansible...@googlegroups.com
I've got a play that ensures some servers are created, then ensures a
domain for those servers exists in DNS, then ensures A records exist
within that domain for each server.

I want the domain ensure to run once, not 10x time, so I have a
construct like:

when: inventory_hostname == play_hosts[0]

so that it only runs on the first host of the play.

This works, so long as that first host doesn't have a failure ensuring
that it exists.

This is pretty awkward, and I'm wondering what other folks have for a
"run once" construct.

I had thought about touching a file locally when the DNS API call is
done to create the domain, but that's racy, because this is a multi-fork
play so multiple forks would be attempting this at once.

-jlk

Brian Coca

unread,
Mar 11, 2014, 6:57:04 PM3/11/14
to ansible...@googlegroups.com
for stuff like that i normally have a 'pre play' with hosts: localhost.


--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno

Michael DeHaan

unread,
Mar 11, 2014, 7:54:23 PM3/11/14
to ansible...@googlegroups.com
"This works, so long as that first host doesn't have a failure ensuring that it exists."

Not sure I completely follow this part, do you mean no hosts in the first play?


--
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/CADn%2BHsySMHjRxwpDuR1wT-j5NF7rCkN0A5sDnbs7Mca98DkiZw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Mar 11, 2014, 7:57:26 PM3/11/14
to ansible...@googlegroups.com
@jesse, actually play_hosts[0] will always give you a 'currently working host', the list removes hosts that have errored out of the play.

it cannot save you if the target host suddenly becomes an issue, i would try do/until then.

Jesse Keating

unread,
Mar 12, 2014, 1:07:10 AM3/12/14
to ansible...@googlegroups.com
On 3/11/14, 4:54 PM, Michael DeHaan wrote:
> "This works, so long as that first host doesn't have a failure ensuring
> that it exists."
>
> Not sure I completely follow this part, do you mean no hosts in the
> first play?


No, I mean that the host it is attempting to run the task on didn't
finish the first task which has required data for the second task. So it
tries to use data that doesn't exist, and boom.

Will follow up more on Brian's reply.


-jlk

Jesse Keating

unread,
Mar 12, 2014, 1:08:35 AM3/12/14
to ansible...@googlegroups.com
Oh! That's amazing. I told a small lie in my first mail, the play book
currently has:

when: inventory_hostname == hostvars.keys()[0]

because it was written before play_hosts existed. Now that we're going
to have access to play_hosts I'll switch all my tasks like this over,
and we'll avoid the current issue that came up today.

Thanks for the info!


-jlk
Reply all
Reply to author
Forward
0 new messages