All information about file entries is stored in the manifest file hamstercage.yaml
. This YAML file consists of these top-level entries:
hosts
: each entry describes one host, in particular the set of tags that apply to ittags
: each entry contains a list of files managed for this tag
This is a very minimal example with one host, one tag and one file:
hosts:
testing.example.com:
description: ''
tags:
- all
tags:
all:
description: files that apply to all hosts
entries:
/etc/profile:
group: root
mode: 0o444
owner: root
type: file
Hosts
Each entry in this dict defines one host. Hosts are distinguished by their fully-qualified hostname. When running Hamstercage, you can override the hostname by specifying the -h
option. Each host definition can have these fields:
description
: allows you to add a description or note to this entry. Optional.tags
: a list of one or more tags to apply to this host.
Tags
Each entry in this dict defines one tag. Tag names can be freely chosen; it is recommended to stick to alpha-numeric identifiers though, to keep the names compatible with shell scripts, etc. Each entry has these fields:
description
: allows you to add a description or note to this entry. Optional.entries
: a dict of files managed through this tag. See below for details.hooks
: a dict of hook scripts that will be run. See below for details.
Tags: Entries
The entries field in a tag entry describes files, directories, and symbolic links that are managed through that tag. Each entry can have these fields:
group
: the group name owning this file.mode
: the access mode for this file. You need to specify the mode as an octal number (0o644
) or as a string in quotes ("644"
). If you simply give a number, it will be interpreted as a base-10 integer, leading to unexpected mode bitsowner
: the user name owning this file.target
: the path the link points to, only applicable totype
=link
type
: must be one ofdir
,file
, orlink
.
Note that Hamstercage only manages symbolic links (soft links). Hard links are not supported.
Tags: Hooks
The hooks
dict in a tag allows you to hook scripts into Hamstercages execution. The name of each entry defines when to run the script; the contents of the dict define what command to execute.
The name consists of two parts separated by a dash: the prefix pre
or post
, and the name of the Hamstercage command. For example, the hook defined by the name pre-save
will be executed when you run hamstercage save
, just before the contents of the files will be copied from the target system to the repository. A hook post-apply
will be run right after all files have been updated by the command hamstercage apply
.
Hamstercage searches for a matching hook definition in this order:
- for the exact match step
-
command (for example,pre-save
) - for the wildcard match
*-
command (for example,*-save
) - for the wildcard match step
-*
(for example,pre-*
) - for the fallback wildcard
*
.
Only the first match found will be executed.
Each entry has these fields:
command
: the command or script to execute.description
: allows you to add a description or note to this entry. Optional.type
: the type of command or script to run.exec
: run the program specified bycommand
. Ifcommand
is not an absolute path, the system will search for it on thePATH
. See subprocess.Popen for details. The command will be invoked with the Hamstercage command, the step, and the tag the hook is defined in as parameters, for example.../myhook.sh apply post all
.python
:command
should specify a Python script. A relative path is interpreted relative to the repository directory. See below for global variables available to the script.shell
: runcommand
through the shell. Typically, this will be the shell of the user running Hamstercage.
The exec
and shell
hooks receive the following environment variables:
HAMSTERCAGE_CMD
: the command being executedHAMSTERCAGE_MANIFEST
: the manifest file path nameHAMSTERCAGE_HOOK
: the name of the hook entryHAMSTERCAGE_REPO
: the repo directory, which is the directory the manifest file lives inHAMSTERCAGE_STEP
: the step (pre
orpost
)HAMSTERCAGE_TAG
: the tag name this hook is defined in
The python
script receives these global variables:
cmd
: the command being executedmanifest
: the manifest objecthook
: the name of the hook entryrepo
: the repo directory, which is the directory the manifest file lives instep
: the step (pre
orpost
)tag
: the tag object this hook is defined in__file__
: the Python hook file__name__
: the constant__hamstercage__
.