force file creation with template module

I need to repair some templated files from a previous playbook execution

##### this is a test #########################################

  - name: my template TEST - template postgres.conf
    vars:
      - pg_service_name: "{{ item }}"
    ansible.builtin.template:
      src: 00-ina-default.conf.j2 # 10-pg-service.conf
      dest: "/home/postgres/{{ pg_service_name }}/00-ina-default.conf"
      owner: postgres
      group: postgres
      force: true
      backup: true
      mode: 0600
    become: true
    loop:
      - somedir

##### this was a test ########################################

this works whether dest does not exist. I want to overwrite an existing file though. This file possibly is or is not identical.

Can it be the force only works when the new and the old file differ?

Ansible describes a state. In your case you want a file to look a certain way. The task will compare the output of the derived template with the existing file. If the existing file matches, no change is made. If the existing file differs or does not exist, it is overwritten or created. You don't need the "force" param.

Walter

that makes sense, tx.

In which kind of situatoin is force: true then even relevant?

I would say force: true might be used when you simply want to force every system to get an update regardless of whether the existing file matches the template. I cannot think of a case where I personally would need that, but someone clearly thought this might be needed so the param is there.

Walter