# Delegate\_to register when

**URL:** <https://forum.ansible.com/t/delegate-to-register-when/20791>\
**Category:** Ansible Project\
**Created:** [March 7, 2016, 1:54pm UTC](https://forum.ansible.com/t/delegate-to-register-when/20791 "2016-03-07T13:54:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Irvine](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Steve\_Irvine](https://forum.ansible.com/u/Steve_Irvine)\
**Post date:** [March 7, 2016, 1:54pm UTC](https://forum.ansible.com/t/delegate-to-register-when/20791/1 "2016-03-07T13:54:27Z")

</div>

Hi Everyone,

Quick question, I have a play where I put a laravel queue system in maintenance mode before running updates against it’s consumers.

I’d like to check for the existence of a file with stat on the queue manager, run it if it exists (it might not be there if this is the first run and it hasn’t been deployed yet).

I’ve tried:

`

# If artisan exists, then set the application into maint. mode

- name: checking for artisan’s existance in current symlink  
stat: path={{ hostvars[item].www\_dir }}/current/artisan  
register: artisan\_current  
delegate\_to: “{{ item }}”  
with\_items: groups.queue\_managers

# This makes sure we don’t keep serving an old release from the pool if the deployment fails

# NGinx doesn’t use the symlink so might keep serving from an old path

- name: set maint.mode in current version  
command: php {{ hostvars[item].www\_dir }}/current/artisan down  
when: artisan\_current.stat.exists is defined and artisan\_current.stat.exists  
delegate\_to: “{{ item }}”  
with\_items: groups.queue\_managers

`

and

`

- name: checking for artisan’s existance in current symlink  
stat: path={{ hostvars[item].www\_dir }}/curthe rent/artisan  
register: hostvars[item].artisan\_current  
delegate\_to: “{{ item }}”  
with\_items: groups.queue\_managers

- name: set maint.mode in current version  
command: php {{ hostvars[item].www\_dir }}/current/artisan down  
when: hostvars[item].artisan\_current.stat.exists is defined and hostvars[item].artisan\_current.stat.exists  
delegate\_to: “{{ item }}”  
with\_items: groups.queue\_managers  
`

Whatever happens, I can see the stat return “exists: true”, and then the conditional check fails:

```auto

build 07-Mar-2016 11:57:06 TASK [checking for artisan's existance in current symlink] ********************* 
build 07-Mar-2016 11:57:07 ok: [redacted -> redacted] => (item=redacted) => {"changed": false, "item": "redacted", "stat": {"atime": 1457350038.6739905, "checksum": "659b7d3cb04a4d3b4fd58cb147c2c9b33e0ea831", "ctime": 1457349988.065974, "dev": 64769, "exists": true, ...lots more output here...}} 
build 07-Mar-2016 11:57:07 build 07-Mar-2016 11:57:07 TASK [set maint.mode in current version] *************************************** 
build 07-Mar-2016 11:57:07 skipping: [redacted] => (item=redacted) => {"changed": false, "item": "redacted", "skip_reason": "Conditional check failed", "skipped": true}

```

```auto
Can anyone help me work out where the register actually puts the results of the stat and therefore how I can present the results to the when: statement.

```

```auto

```

```auto
Thanks,

```

```auto

```

```auto
Steve

```

---

<div class="post-metadata">

**Author:** ![Steve\_Irvine](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Steve\_Irvine](https://forum.ansible.com/u/Steve_Irvine)\
**Post date:** [March 7, 2016, 3:01pm UTC](https://forum.ansible.com/t/delegate-to-register-when/20791/2 "2016-03-07T15:01:30Z")

</div>

Hi All,

I found this link:

[https://docs.ansible.com/ansible/playbooks\_loops.html#using-register-with-a-loop](https://docs.ansible.com/ansible/playbooks_loops.html#using-register-with-a-loop)

Which suggests that once register is run with a loop the output goes into a structure called results.

I tried:

artisan\_current.results[item].stat.exists ?

Still no go.

---

<div class="post-metadata">

**Author:** ![Kristofer\_Borgstrom](https://avatars.discourse-cdn.com/v4/letter/k/47e85d/32.png) [@Kristofer\_Borgstrom](https://forum.ansible.com/u/Kristofer_Borgstrom)\
**Post date:** [November 7, 2018, 10:56am UTC](https://forum.ansible.com/t/delegate-to-register-when/20791/3 "2018-11-07T10:56:36Z")

</div>

Hey!

Although this post is very old, I have run into much the same problem. did you ever find a solution?

Cheers,  
Kristofer
