salt.states.file

absent

salt.states.file.absent(name)

Verify that the named file or directory is absent, this will work to reverse any of the functions in the file state module.

name
The path which should be deleted

append

salt.states.file.append(name, text)

Ensure that some text appears at the end of a file

The text will not be appended again if it already exists in the file. You may specify a single line of text or a list of lines to append.

Multi-line example:

/etc/motd:
  file.append:
    - text: |
        Thou hadst better eat salt with the Philosophers of Greece,
        than sugar with the Courtiers of Italy.
        - Benjamin Franklin

Multiple lines of text:

/etc/motd:
  file.append:
    - text:
      - Trust no one unless you have eaten much salt with him.
      - Salt is born of the purest of parents: the sun and the sea.

New in version 0.9.5.

comment

salt.states.file.comment(name, regex, char='#', backup='.bak')

Usage:

/etc/fstab:
  file.comment:
    - regex: ^bind 127.0.0.1

New in version 0.9.5.

directory

salt.states.file.directory(name, user=None, group=None, recurse=[], mode=None, makedirs=False, clean=False, require=None)

Ensure that a named directory is present and has the right perms

name
The location to create or manage a directory
user
The user to own the directory, this defaults to the user salt is running as on the minion
group
The group ownership set for the directory, this defaults to the group salt is running as on the minion
recurse
Enforce user/group ownership of directory recursively
mode
The permissions to set on this directory, aka 755
makedirs
If the directory is located in a path without a parent directory, then the state will fail. If makedirs is set to True, then the parent directories will be created to facilitate the creation of the named file.
clean
Make sure that only files that are set up by salt and required by this function are kept. If this option is set then everything in this directory will be deleted unless it is required.
require
Require other resources such as packages or files

managed

salt.states.file.managed(name, source=None, source_hash='', user=None, group=None, mode=None, template=None, makedirs=False, context=None, replace=True, defaults=None, env=None, **kwargs)

Manage a given file, this function allows for a file to be downloaded from the salt master and potentially run through a templating system.

name
The location of the file to manage
source

The source file to download to the minion, this source file can be hosted on either the salt master server, or on an http or ftp server. For files hosted on the salt file server, if the file is located on the master in the directory named spam, and is called eggs, the source string is salt://spam/eggs. If source is left blank or None, the file will be created as an empty file and the content will not be managed

If the file is hosted on a http or ftp server then the source_hash argument is also required

source_hash:
This can be either a file which contains a source hash string for the source, or a source hash string. The source hash string is the hash algorithm followed by the hash of the file: md5=e138491e9d5b97023cea823fe17bac22
user
The user to own the file, this defaults to the user salt is running as on the minion
group
The group ownership set for the file, this defaults to the group salt is running as on the minion
mode
The permissions to set on this file, aka 644, 0775, 4664
template
If this setting is applied then the named templating engine will be used to render the downloaded file, currently jinja and mako are supported
makedirs
If the file is located in a path without a parent directory, then the state will fail. If makedirs is set to True, then the parent directories will be created to facilitate the creation of the named file.
replace
If this file should be replaced, if false then this command will be ignored if the file exists already. Default is true.
context
Overrides default context variables passed to the template.
defaults
Default context passed to the template.

nested

salt.states.file.nested(*args, **kwds)

Combine multiple context managers into a single nested context manager.

This function has been deprecated in favour of the multiple manager form of the with statement.

The one advantage of this function over the multiple manager form of the with statement is that argument unpacking allows it to be used with a variable number of context managers as follows:

with nested(*managers):
do_something()

recurse

salt.states.file.recurse(name, source, clean=False, require=None, user=None, group=None, dir_mode=None, file_mode=None, env=None, include_empty=False, **kwargs)

Recurse through a subdirectory on the master and copy said subdirecory over to the specified path.

name
The directory to set the recursion in
source
The source directory, this directory is located on the salt master file server and is specified with the salt:// protocol. If the directory is located on the master in the directory named spam, and is called eggs, the source string is salt://spam/eggs
clean
Make sure that only files that are set up by salt and required by this function are kept. If this option is set then everything in this directory will be deleted unless it is required.
require
Require other resources such as packages or files
user
The user to own the directory, this defaults to the user salt is running as on the minion
group
The group ownership set for the directory, this defaults to the group salt is running as on the minion
dir_mode
The permissions mode to set any directories created
file_mode
The permissions mode to set any files created
include_empty
Set this to True if empty directories should also be created (default is False)

sed

salt.states.file.sed(name, before, after, limit='', backup='.bak', options='-r -e', flags='g')

Maintain a simple edit to a file

The file will be searched for the before pattern before making the edit and then searched for the after pattern to verify the edit was successful using salt.modules.file.contains. In general the limit pattern should be as specific as possible and before and after should contain the minimal text to be changed.

Usage:

# Disable the epel repo by default
/etc/yum.repos.d/epel.repo:
  file.sed:
    - before: 1
    - after: 0
    - limit: ^enabled=

# Remove ldap from nsswitch
/etc/nsswitch.conf:
  file.sed:
    - before: 'ldap'
    - after: ''
    - limit: '^passwd:'

New in version 0.9.5.

touch

salt.states.file.touch(name, atime=None, mtime=None, makedirs=False)

Replicate the 'nix "touch" command to create a new empty file or update the atime and mtime of an existing file.

Usage:

/var/log/httpd/logrotate.empty:
  file.touch

New in version 0.9.5.

uncomment

salt.states.file.uncomment(name, regex, char='#', backup='.bak')

Usage:

/etc/adduser.conf:
  file.uncomment:
    - regex: EXTRA_GROUPS

New in version 0.9.5.

urlparse

salt.states.file.urlparse(url, scheme='', allow_fragments=True)

Parse a URL into 6 components: <scheme>://<netloc>/<path>;<params>?<query>#<fragment> Return a 6-tuple: (scheme, netloc, path, params, query, fragment). Note that we don't break the components up in smaller bits (e.g. netloc is a single string) and we don't expand % escapes.

Parent topic

Table Of Contents

Previous topic

salt.states.cron

Next topic

salt.states.gem