Salt States: Creating empty files without managed function

1,879 views
Skip to first unread message

Jonas Kaufmann

unread,
Jan 13, 2012, 8:45:14 AM1/13/12
to salt-...@googlegroups.com
Hello,

I am looking for a way to create empty files in a salt state (just like "touch myfile"). So far I could only find the option to create files in managed mode. I am basically looking for a way like this:

/var/log/dummy.log:
  file:
    - touch
    - user: www-data
    - group: www-data
    - mode: 777

I need this to make sure that some files exist and have the right permissions set. Is there any option I am missing?

Best regards,
Jonas

Thomas S Hatch

unread,
Jan 13, 2012, 10:17:31 AM1/13/12
to salt-...@googlegroups.com
Yes, we need to add this to managed or add a new function. I will make this an issue for 0.9.6.

right now the best way will still be to have an empty file on the file server:
/var/log/dummy.log:
  file:
    - managed
    - source: salt://dummy-file/empty
    - user: www-data
    - group: www-data
    - mode: 777

Jeff Schroeder

unread,
Jan 13, 2012, 4:05:35 PM1/13/12
to salt-...@googlegroups.com

I liked this feature enough to implement it two ways for you[1].

/tmp/newfile.state:
file:
- touch
- mtime: 1326488608.326422
- atime: 1326488608.326422

/tmp/empty:
file:
- managed
- user: jeff
- group: jeff

You can set explicit atime & ctime with "touch" or you can create an
empty file with the permissions and ownership you want using the
regular managed file state. Now you can also do:

salt '*' file.touch /tmp/newfile.txt

Thanks for the idea! Now hopefully tom will accept this pull request.

[1] https://github.com/saltstack/salt/pull/504


--
Jeff Schroeder

Don't drink and derive, alcohol and analysis don't mix.
http://www.digitalprognosis.com

Thomas S Hatch

unread,
Jan 13, 2012, 4:08:19 PM1/13/12
to salt-...@googlegroups.com
I guess I will accept that :)

I have tested a little, but have not put this into the qa env yet. Thanks!

Jonas Kaufmann

unread,
Jan 14, 2012, 6:19:08 AM1/14/12
to salt-...@googlegroups.com
Thanks Jeff and Thomas, this seems like exactly what I was looking for! Great! Will this feature be available in the 0.9.5 release or in a later release?

Jonas

Thomas S Hatch

unread,
Jan 14, 2012, 10:06:33 AM1/14/12
to salt-...@googlegroups.com
This will be in 0.9.5!
Reply all
Reply to author
Forward
0 new messages