How to emulate Make semantics?

27 views
Skip to first unread message

Cev Ing

unread,
Jan 26, 2017, 6:24:26 AM1/26/17
to Ansible Project
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?

Johannes Kastl

unread,
Jan 26, 2017, 6:34:08 AM1/26/17
to ansible...@googlegroups.com
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

signature.asc

Cev Ing

unread,
Jan 26, 2017, 10:30:58 AM1/26/17
to Ansible Project


Am Donnerstag, 26. Januar 2017 12:34:08 UTC+1 schrieb Johannes Kastl:

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). 

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

Johannes Kastl

unread,
Jan 26, 2017, 10:37:55 AM1/26/17
to ansible...@googlegroups.com
On 26.01.17 16:30 Cev Ing wrote:

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

Why not, what error are you getting?

> 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


signature.asc

Cev Ing

unread,
Jan 26, 2017, 10:45:30 AM1/26/17
to Ansible Project


Am Donnerstag, 26. Januar 2017 16:37:55 UTC+1 schrieb Johannes Kastl:
On 26.01.17 16:30 Cev Ing wrote:

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

Why not, what error are you getting?

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.

Johannes Kastl

unread,
Jan 26, 2017, 11:20:06 AM1/26/17
to ansible...@googlegroups.com
On 26.01.17 16:45 Cev Ing wrote:

> 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.
>
Without the actual error (and your playbook) it is hard to guess...

Johannes

signature.asc
Reply all
Reply to author
Forward
0 new messages