How to ensure directory contents?

76 views
Skip to first unread message

Tom Vaughan

unread,
Apr 5, 2012, 4:06:44 PM4/5/12
to salt-...@googlegroups.com
First, thanks for salt. This:


used to be a rather hairy set of shell scripts. I tried to convert this to puppet. Tried, that is. But the conversion to salt was simple and enjoyable.

As I just started this yesterday, I'm sure there is a lot I did "wrong". I'd appreciate any feedback on this, especially in regards to how this "should" be done in an idiomatic way.

One question, I add apt sources to /etc/apt/sources.list.d. Is there a way I can say "ensure that this directory only contains a certain set of files"?

Best.

-Tom


Thomas S Hatch

unread,
Apr 5, 2012, 4:21:19 PM4/5/12
to salt-...@googlegroups.com
To ensure that there are only managed files in a directory, use file.directory,  require all of the files that to be kept, and set clean to True:

/etc/apt/sources-list.d/some.repo:
  file:
    - managed
    - source: salt://foo

/etc/apt/sources-list.d/:
  file:
    - directory
    - clean: True
    - require:
      - file: /etc/apt/sources-list.d/some.repo

The clean option in file.directory clears any files out a a directory that are not required.

Other than that your layout is a little different, normally it has modules in init.sls files in directories, it makes the layout more flexible for the future.  A great example is the blast-hardcheese repos:
https://github.com/blast-hardcheese/blast-salt-states

Tom Vaughan

unread,
Apr 5, 2012, 4:24:29 PM4/5/12
to salt-...@googlegroups.com
Cool. Thanks!

-Tom


On Thursday, April 5, 2012 5:21:19 PM UTC-3, Thomas Hatch wrote:
To ensure that there are only managed files in a directory, use file.directory,  require all of the files that to be kept, and set clean to True:

/etc/apt/sources-list.d/some.repo:
  file:
    - managed
    - source: salt://foo

/etc/apt/sources-list.d/:
  file:
    - directory
    - clean: True
    - require:
      - file: /etc/apt/sources-list.d/some.repo

The clean option in file.directory clears any files out a a directory that are not required.

Other than that your layout is a little different, normally it has modules in init.sls files in directories, it makes the layout more flexible for the future.  A great example is the blast-hardcheese repos:
https://github.com/blast-hardcheese/blast-salt-states

Thomas S Hatch

unread,
Apr 5, 2012, 4:35:07 PM4/5/12
to salt-...@googlegroups.com
Thank you Tom, I really like to see sls files online, it really helps us get out there more!
Reply all
Reply to author
Forward
0 new messages