# stat path meta character and register best practice

**URL:** <https://forum.ansible.com/t/stat-path-meta-character-and-register-best-practice/16793>\
**Category:** Ansible Project\
**Created:** [November 14, 2014, 8:12pm UTC](https://forum.ansible.com/t/stat-path-meta-character-and-register-best-practice/16793 "2014-11-14T20:12:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![faust](https://avatars.discourse-cdn.com/v4/letter/f/c89c15/32.png) [@faust](https://forum.ansible.com/u/faust)\
**Post date:** [November 14, 2014, 8:12pm UTC](https://forum.ansible.com/t/stat-path-meta-character-and-register-best-practice/16793/1 "2014-11-14T20:12:06Z")

</div>

Hi,  
is it possible to use the stat module with meta characters:

`

- stat: path=/etc/rc2.d/S\*init\_script.sh  
register: i

- debug: msg=“Path is a simlink”  
when: i.stat.islnk

`

Or what is the elegant way of doing the following (without breaking the very useful ‘ansible-playbook --check’ feature):

`

- name: check init script present  
shell: if test -f /etc/rc2.d/S\*`init_script`.sh ; then echo true; fi  
register: result  
ignore\_errors: true  
changed\_when: false

- name: install init script  
shell: /usr/sbin/update-rc.d `init_script`.sh remove && /usr/sbin/update-rc.d `init_script`.sh defaults  
when: result.stdout != ‘true’

`

I am trying to configure Debian init script.  
Regards.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [November 17, 2014, 8:38pm UTC](https://forum.ansible.com/t/stat-path-meta-character-and-register-best-practice/16793/2 "2014-11-17T20:38:32Z")

</div>

The stat module cannot take fileglobs, and must check a specific asset.

What you have with the test is probably reasonable.

---

<div class="post-metadata">

**Author:** ![Tore\_Olsen](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@Tore\_Olsen](https://forum.ansible.com/u/Tore_Olsen)\
**Post date:** [November 18, 2014, 12:45pm UTC](https://forum.ansible.com/t/stat-path-meta-character-and-register-best-practice/16793/3 "2014-11-18T12:45:14Z")

</div>

I just solved this differently by using the creates argument to the shell module. In my opinion you should _know_ the name of the S and K symlinks so a wildcard shouldn’t be necessary. Here’s my approach:

- shell: update-rc.d myinitscript defaults  
args:  
creates: /etc/rc2.d/S20myinitscript

This will skip the update-rc.d if the symlink already exists. It will actually be skipped if its’ a regular file or a directory too, but I’m not that paranoid. (Or you’d have to check each symlink that you expect to be created.) Test what’s reasonably going to break, that’s my philosophy here.

Regards,  
Tore

---

<div class="post-metadata">

**Author:** ![faust](https://avatars.discourse-cdn.com/v4/letter/f/c89c15/32.png) [@faust](https://forum.ansible.com/u/faust)\
**Post date:** [November 19, 2014, 1:59pm UTC](https://forum.ansible.com/t/stat-path-meta-character-and-register-best-practice/16793/4 "2014-11-19T13:59:06Z")

</div>

@Michael:  
Thanks for the confirmation about the stat module.  
I am migrating from puppet and I must admit that Ansible is winning on lot’s of aspects but these kind of things were a bit more easy/elegant to accomplish with puppet. May we find some work around in the next modules versions.

@Tore:  
Interesting approach, I did not knew this shell module option.

But regarding init script I prefer to let lsb directives and update-rc.d tool taking care of the boot/shutdown order. I think this way, it is easier to work with different platforms and above all with big DevOps teams.

I’ll let you know if I find something in between (but I am not going to search too much as systemd is coming :))

Regards,  
Faust
