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

**URL:** <https://forum.ansible.com/t/how-can-i-iterate-until-i-find-a-unique-file-name-git-tag-using-ansible/14786>\
**Category:** Ansible Project\
**Created:** [March 15, 2014, 11:09pm UTC](https://forum.ansible.com/t/how-can-i-iterate-until-i-find-a-unique-file-name-git-tag-using-ansible/14786 "2014-03-15T23:09:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Holywell](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Simon\_Holywell](https://forum.ansible.com/u/Simon_Holywell)\
**Post date:** [March 15, 2014, 11:09pm UTC](https://forum.ansible.com/t/how-can-i-iterate-until-i-find-a-unique-file-name-git-tag-using-ansible/14786/1 "2014-03-15T23:09:45Z")

</div>

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](https://twitter.com/Treffynnon/status/444536025957015552) and was asked to post here instead.

Thanks,  
Simon
