Questions about file copy / modification

Hello everybody !

I’m kind of new around here and a fresh new Ansible user ! So my questions may sounds little bit stupid…
Anyway ! My environment is the following : I’m using ansible to manage VM behind a bastion. So I have a ssh.cfg file with ProxyCommand in it etc.
Everything is working but this is slow ! And this is actually normal.

Still, I was wondering how exactly copy / unarchive / file modules are proceeding.
Let’s assume that I have a httpd.conf file deployed on my VM. Everytime I’m running my playbook with the copy module with a httpd.conf file as src parameter, what is going to happen ?
Is Ansible going to check if modifications have been done ? Or is Ansible simply replacing the file ?
I’m asking these questions because when I run my playbook, I get the “ok” status for the copy task but couldn’t find anything about it ! I really want to make sure that ansible isn’t doing anything that could slow down my general deployment.

Indeed, I want to know what is better in term of speed :

  • Use the copy module directly
    OR
  • add a WHEN condition to the copy task and have a rapid checksum using stat module before running the copy ?

Basically, my general question is :

What is actually doing copy / file (symlink use case) / unarchive modules whereas the version on the remote server is the same as the local one !

My goal is to avoid any useless operations in order to minimize the time of my playbook run.

So that I have an answer to this question : Is it worth using different stat module in order to determine if I should run a task or not ?

As an example, is it better to perform this :

  • name: Checking if the link has to be updated
    stat:
    path: “{{ ihm_symlink_name }}”
    register: ihm_lnk_stat

  • name: Update the {{ name }} symlink to point at the new folder
    file:
    src: “{{ folder_path }}”
    dest: “{{ symlink_name }}”
    state: link

when: ihm_lnk_stat.stat.lnk_target != “{{ folder_path }}”

OR simply that :

  • name: Update the {{ name }} symlink to point at the new folder
    file:
    src: “{{ folder_path }}”
    dest: “{{ symlink_name }}”
    state: link

I hope you see what I mean and why I’m asking me this question ! If not, please tell me, I’ll try to rephrase !
Thank you for reading me !