Hm there doesn't seem to be any easy way to truncate files with #ansible?
I know I can delete, and recreate files, but I want permissions/file ownership/selinux all to be preserved.

Follow

@mhamzahkhan

Pure Ansible solution would be as follows:

- name: ensure file exists
copy:
content: ""
dest: /etc/nologin
force: true

Ansible-lint will whine about the user, group and chmod not specified explicitly but it can be ignored with # noqa annotation since your objective is to specifically preserve the existing permissions.

@kravietz Ah! I like that better. I will give it a shot. Thank you!

Sign in to participate in the conversation
Mastodon 🔐 privacytools.io

Fast, secure and up-to-date instance. PrivacyTools provides knowledge and tools to protect your privacy against global mass surveillance.

Website: privacytools.io
Matrix Chat: chat.privacytools.io
Support us on OpenCollective, many contributions are tax deductible!