Resources

Resources describe the desired state of your infrastructure. Each resource represents something to manage and is backed by a provider that implements platform-specific management logic.

Every resource has a type, a unique name, and resource-specific properties.

Resource Types

  • Archive - Download, extract and copy files from tar.gz and zip archives
  • Exec - Idempotent command execution
  • File - Manage files content, ownership and more
  • Package - Install, upgrade, downgrade and remove packages using OS Native packagers
  • Scaffold - Render template directories into target directories with synchronization and purge support
  • Service - Enable, disable, start, stop and restart services using OS Native service managers

Common Properties

All resources support the following common properties:

PropertyDescription
nameUnique identifier for the resource
ensureDesired state (values vary by resource type)
aliasAlternative name for use in subscribe, require, and logging
providerForce a specific provider
requireList of resources (type#name or type#alias) that must succeed first
health_checksHealth checks to run after applying (see Monitoring)
controlConditional execution rules (see below)

Conditional Resource Execution

Resources can be conditionally executed using a control section and expressions that should resolve to boolean values.

package:
  name: zsh
  ensure: 5.9
  control:
    if: lookup("facts.host.info.os") == "linux"
    unless: lookup("facts.host.info.virtualizationSystem") == "docker"
ccm ensure package zsh 5.9 \
    --if "lookup('facts.host.info.os') == 'linux'"
    --unless "lookup('facts.host.info.virtualizationSystem') == 'docker'"
{
  "protocol": "io.choria.ccm.v1.resource.ensure.request",
  "type": "package",
  "properties": {
    "name": "zsh",
    "ensure": "5.9",
    "control": {
      "if": "lookup(\"facts.host.info.os\") == \"linux\"",
      "unless": "lookup(\"facts.host.info.virtualizationSystem\") == \"docker\""
    }
  }
}

Here we install zsh on all linux machines unless they are running inside a docker container.

The following table shows how the two conditions interact:

ifunlessResource Managed?
(not set)(not set)Yes
true(not set)Yes
false(not set)No
(not set)trueNo
(not set)falseYes
truetrueNo
truefalseYes
falsetrueNo
falsefalseNo

About Names

Resources can be specified like:

/etc/motd:
  ensure: present

This sets name to /etc/motd, in the following paragraphs we will refer to this as name.