Creating directories

The directory resource can be used to create a directory and all of its parent directories. Tildes (~) in directory names are supported.

directory '~/this/is/a/directory'

If you want to specify the directory’s mode, owner or group, you can do so via the mode, owner or group attributes.

directory '~/this/is/another/directory',
          mode: '755', (1)
          owner: 'nobody:nobody'
1 wright also supports symbolic mode strings (e.g. 'u=rwx,go=rx'), but numeric notation is often more compact.

Creating files

The file resource can be used to create files. Tildes (~) in file names are supported.

file '~/this-is-a-file'

If you do not specify the file’s desired content, wright creates an empty file if the file does not yet exist but will not touch existing files.[1]

file '~/this-is-another-file',
     content: "Hello world\n",
     mode: '400', (1)
     owner: 'nobody:nobody'
1 wright also supports symbolic mode strings (e.g. 'u=r,go='), but numeric notation is often more compact.

If you would like to render a template, you can do so using the render_erb and render_mustache helpers.

file '~/this-is-an-erb-file',
     content: util.render_erb("Hello <%= name %>\n", name: 'ERB world')

file '~/this-is-a-mustache-file',
     content: util.render_mustache("Hello {{name}}\n", name: 'Mustache world')

To render a template file, you can use the render_file helper.

file '~/hello.mustache', content: "Hello {{name}}\n"

file '~/this-is-another-mustache-file',
     content: util.render_file('~/hello.mustache', name: 'Mustache world')

Creating groups

The group resource can be used to create groups.

group 'ordinary_gentlemen'

If you want to add members to a group, change the group’s group id or create the group as a system group, you can use the gid, members and system attributes.

group 'extraordinary_gentlemen',
      gid: 999,
      members: %w(murray quatermain nemo jekyll), (1)
      system: false
1 Note that wright removes all users that are not listed here from the group’s members list.

Creating users

The user resource can be used to create users.

user 'orlando'

If you want to change a user’s details, you can set the user resource’s attributes.

user 'griffin',
     uid: 777,
     full_name: 'Hawley Griffin',
     home: '/home/users/griffin',
     groups: 'extraordinary_gentlemen',
     primary_group: 'users',
     shell: 'zsh',
     system: false

All user attributes are optional and have sensible defaults. For example on GNU systems, useradd(8) is used to create users, which is why wright respects all your sytem-wide user defaults.

The symlink resource can be used to create symlinks.

symlink '/etc/nginx/sites-enabled/example.org',
        to: '/etc/nginx/sites-available/example.org'

Installing packages

The package resource can be used to install packages.

package 'tmux'

While wright defaults to installing the package version picked by your package manager, you can also use the version attribute to specify the desired version. The options attribute can be used to pass options to your package manager.

package 'mg',
        version: '20110905-1.1',
        options: %w(--no-install-recommends --auto-remove) (1)
1 If you only need a single option, you can also set options to a string such as '--no-install-recommends'.

1. If you want to clear the content of an existing file, you can set the file’s content attribute to empty string.