force file creation with template module

448 views
Skip to first unread message

dulh...@mailbox.org

unread,
Nov 10, 2022, 8:41:58 AM11/10/22
to ansible...@googlegroups.com
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?

Rowe, Walter P. (Fed)

unread,
Nov 10, 2022, 8:50:03 AM11/10/22
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F1890057150.554463.1668087697988%2540office.mailbox.org&data=05%7C01%7Cwalter.rowe%40nist.gov%7Ccb06f06277a84f7179a308dac3214f60%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638036845095155999%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=89Yh%2BMkgT0%2BB6aq8puog46RalpHHDCbMlfsGdbzYob4%3D&reserved=0.

dulh...@mailbox.org

unread,
Nov 10, 2022, 9:11:00 AM11/10/22
to ansible...@googlegroups.com
that makes sense, tx.

In which kind of situatoin is force: true then even relevant?
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/E1101E15-2062-410F-92BD-3CE85D5808D2%40nist.gov.

Rowe, Walter P. (Fed)

unread,
Nov 10, 2022, 9:21:05 AM11/10/22
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
To view this discussion on the web visit https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F1890057150.554463.1668087697988%2540office.mailbox.org&data=05%7C01%7Cwalter.rowe%40nist.gov%7C858d356ab1484130c65c08dac325600b%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638036862548360143%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=ixx5qVf%2F30AZUwOxzss65mD5Wixv6L%2Bro7PBBN2pJtg%3D&reserved=0.

-- 
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FE1101E15-2062-410F-92BD-3CE85D5808D2%2540nist.gov&data=05%7C01%7Cwalter.rowe%40nist.gov%7C858d356ab1484130c65c08dac325600b%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638036862548360143%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=FT2cbRNen1deUHvETb6yfrTOUpDZCx89T1iLtKjbEIo%3D&reserved=0.

-- 
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F1698410404.557814.1668089444248%2540office.mailbox.org&data=05%7C01%7Cwalter.rowe%40nist.gov%7C858d356ab1484130c65c08dac325600b%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638036862548360143%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=wbYBKkKZW2L01Prwdo5%2B6A7ba68cvY0GV75z4edtIRU%3D&reserved=0.

Reply all
Reply to author
Forward
0 new messages