Follow

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

@mhamzahkhan if nothing else you can have it run trunc via a shell call

@mhamzahkhan can't you use the shell tool for it, using the command module?

@sheogorath Yep, that's what I'm trying to do but it's not working very well for me :(
paste.centos.org/view/35fbe3dd

I've tried using truncate -s0 , and also cat /dev/null > {{ item }} but for some reason, it's appending a , to the file. Any ideas?

@sheogorath Nevermind! I'm an idiot. It should be {{ item.path }} 🤦‍♂️

@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@intahnet.co.uk

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!