# How to emulate Make semantics?

**URL:** <https://forum.ansible.com/t/how-to-emulate-make-semantics/23565>\
**Category:** Ansible Project\
**Created:** [January 26, 2017, 11:24am UTC](https://forum.ansible.com/t/how-to-emulate-make-semantics/23565 "2017-01-26T11:24:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cev\_Ing](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@Cev\_Ing](https://forum.ansible.com/u/Cev_Ing)\
**Post date:** [January 26, 2017, 11:24am UTC](https://forum.ansible.com/t/how-to-emulate-make-semantics/23565/1 "2017-01-26T11:24:26Z")

</div>

I need to execute a play, which uses file A to generate file B, if B does not exist or if B exists and is older than A.

How can I compare file dates in the when condition?

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 26, 2017, 11:33am UTC](https://forum.ansible.com/t/how-to-emulate-make-semantics/23565/2 "2017-01-26T11:33:52Z")

</div>

Cleanest solution would be to use two stat commands with "register:  
file\_A" and compare those variables (I guess file\_A.stat.mtime might  
work).

Johannes

---

<div class="post-metadata">

**Author:** ![Cev\_Ing](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@Cev\_Ing](https://forum.ansible.com/u/Cev_Ing)\
**Post date:** [January 26, 2017, 3:30pm UTC](https://forum.ansible.com/t/how-to-emulate-make-semantics/23565/3 "2017-01-26T15:30:58Z")

</div>

Using stat in a local action with become does not seem to work. Shell seems to be the only module, which works with become in local actions. This works with become:

shell: |-  
test -e {{ users\_pw\_hash }} -a {{ users\_pw\_hash }} -nt /etc/shadow ||  
echo needs\_update  
register: etc\_shadow\_result  
delegate\_to: 127.0.0.1

become: true

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 26, 2017, 3:37pm UTC](https://forum.ansible.com/t/how-to-emulate-make-semantics/23565/4 "2017-01-26T15:37:34Z")

</div>

> Using stat in a local action with become does not seem to work.

Why not, what error are you getting?

> &nbsp;&nbsp;delegate\_to: 127.0.0.1

I am not sure, but I thing I remember there is a difference between  
"delegate\_to: 127.0.0.1" and "delegate\_to: localhost". If there is, I  
do not know if this has an impact on your task...

Johannes

---

<div class="post-metadata">

**Author:** ![Cev\_Ing](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@Cev\_Ing](https://forum.ansible.com/u/Cev_Ing)\
**Post date:** [January 26, 2017, 3:45pm UTC](https://forum.ansible.com/t/how-to-emulate-make-semantics/23565/5 "2017-01-26T15:45:30Z")

</div>

Maybe I am wrong and stat works, but what does not work is copy. The error is, that copy has no read permission to read /etc/shadow in a local action, although I use become.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 26, 2017, 4:19pm UTC](https://forum.ansible.com/t/how-to-emulate-make-semantics/23565/6 "2017-01-26T16:19:59Z")

</div>

Without the actual error (and your playbook) it is hard to guess...

Johannes
