How can I iterate until I find a unique file name/git tag using Ansible?`

Hi,

I am trying to replicate a deployment strategy in Ansible to replace a few hastily thrown together shell scripts. Perhaps some of this would normally be handled by a CI setup, but we don’t currently have one and there are over a hundred projects this will be applied to.

To this end I am trying to iterate until I find a unique git tag like so:

  • name: tag a new release
    local_action: shell git tag -m deployed deployed-{{ release_tag }}{% if new_release_tag_contents|default(false) != false %}_{{ new_release_tag_contents.attempts }}{% endif %}
    register: new_release_tag_contents
    until: new_release_tag_contents.stdout.find(“already exists”) == -1
    retries: 20
    delay: 1

It would seem that new_release_tag_contents is not available within the local action as it appears to always evaluate to false. Is it possible to access the attempts value in the task? Is there a better way of doing this?

To give you a further idea of the work flow if needed; when a new release takes place we:

  • create a new git tag (for example deployed-2014-03-10)
  • push to bitbucket
  • push to a bare repo on production
  • ssh into production
  • copy previous release folder to new folder (name matches release tag)
  • git pull and checkout release tag
  • symlink new release directory to pub.tmp
  • mv pub.tmp to pub

I tweeted about this over at https://twitter.com/Treffynnon/status/444536025957015552 and was asked to post here instead.

Thanks,
Simon