CHAKE(1) | General Commands Manual | CHAKE(1) |
chake - serverless configuration management tool
chake init
chake [rake arguments]
chake is a tool that helps you manage multiple hosts without the need for a central server. Configuration is managed in a local directory, which should (but doesn't need to) be under version control with git(1) or any other version control system.
Configuration is deployed to managed hosts remotely, either by invoking a configuration management tool that will connect to them, or by first uploading the necessary configuration and them remotely running a tool on the hosts.
chake supports the following configuration management tools:
Beyond applying configuration management recipes on the hosts, chake also provides useful tools to manage multiple hosts, such as listing nodes, running commands against all of them simultaneously, logging in to interactive shells, and others.
$ chake init[:configmanager]
This will create an initial directory structure. Some of the files are specific to your your chosen configmanager, which can be one of [SUPPORTED CONFIGURATION MANAGERS]. The following files, though, will be common to any usage of chake:
If you omit configmanager, itamae will be used by default.
After the repository is created, you can call either chake or rake, as they are completely equivalent.
Just after you created your repository, the contents of nodes.yaml is the following:
host1.mycompany.com:
itamae:
- roles/basic.rb
The exact contents depends on the chosen configuration management tool.
You can list your hosts with rake nodes:
$ rake nodes host1.mycompany.com ssh
To add more nodes, just append to nodes.yaml:
host1.mycompany.com:
itamae:
- roles/basic.rb host2.mycompany.com:
itamae:
- roles/basic.rb
And chake now knows about your new node:
$ rake nodes host1.mycompany.com ssh host2.mycompany.com ssh
Nodes have very few initial requirements to be managed with chake:
A note on password prompts: every time chake calls ssh on a node, you may be required to type in your password; every time chake calls sudo on the node, you may be require to type in your password. For managing one or two nodes this is probably fine, but for larger numbers of nodes it is not practical. To avoid password prompts, you can:
To check whether hosts are correctly configured, you can use the check task:
$ rake check
That will run the the sudo true command on each host. If that pass without you having to type any passwords, it means that:
Note that by default all tasks that apply to all hosts will run in parallel, using rake's support for multitasks. If for some reason you need to prevent that, you can pass -j1 (or --jobs=1) in the rake invocation. Note that by default rake will only run N+4 tasks in parallel, where N is the number of cores on the machine you are running it. If you have more than N+4 hosts and want all of them to be handled in parallel, you might want to pass-j(or--jobs`), without any number, as the last argument; with that rake will have no limit on the number of tasks to perform in parallel.
To apply the configuration to all nodes, run
$ rake converge
To apply the configuration to a single node, run
$ rake converge:$NODE
To apply a single recipe on all nodes, run
$ rake apply[myrecipe]
What recipe is depends on the configuration manager.
To apply a single recipe on a specific node, run
$ rake apply:$NODE[myrecipe]
If you don't inform a recipe in the command line, you will be prompted for one.
To run a shell command on all nodes, run
$ rake run The above will prompt you for a command, then execute it on all nodes.
To pass the command to run in the command line, use the following syntax:
$ rake run[command]
If the command you want to run contains spaces, or other characters that are special do the shell, you have to quote them, for example:
$ rake run["cat /etc/hostname"]
To run a shell command on a specific node, run
$ rake run:$NODE[command]
As before, if you run just rake run:$NODE, you will be prompted for the command.
To list all existing tasks, run:
$ rake -T
As chake supports different configuration management tools, the specifics of configuration management code depends on the the tool you choose. See the corresponding documentation.
Some of the configuration management tools require some software to be installed on the managed hosts. When that's the case, chake acts on a node for the first time, it has to bootstrap it. The bootstrapping process includes doing the following:
The keys in the hash that is represented in nodes.yaml is a node URL. All components of the URL but the hostname are optional, so just listing hostnames is the simplest form of specifying your nodes. Here are all the components of the node URLs:
[connection://][username@]hostname[:port][/path]
You can define rake tasks that will be executed before bootstrapping nodes, before uploading configuration management content to nodes, and before converging. To do this, you just need to enhance the corresponding tasks:
Example:
task :bootstrap_common do
sh './scripts/pre-bootstrap-checks' end
Any files ending matching *.gpg and *.asc will be decrypted with GnuPG before being sent to the node (for the configuration management tools that required files to be sent). You can use them to store passwords and other sensitive information (SSL keys, etc) in the repository together with the rest of the configuration.
For configuration managers that don't require uploading files to the managed node, this decryption will happen right before converging or applying single recipes, and the decrypted files will be wiped right after that.
If you use this feature, make sure that you have the wipe program installed. This way chake will be able to delete the decrypted files in a slightly more secure way, after being done with them.
If you need special SSH configuration parameters, you can create a file called .ssh_config (or whatever file name you have in the $CHAKE_SSH_CONFIG environment variable, see below for details) in at the root of your repository, and chake will use it when calling ssh.
To easily login to one of your host, just run rake login:$HOSTNAME. This will automatically use the repository-local SSH configuration as above so you don't have to type -F .ssh_config all the time.
Some times, you will also want or need to prefix your SSH invocations with some prefix command in order to e.g. tunnel it through some central exit node. You can do this by setting $CHAKE_SSH_PREFIX on your environment. Example:
CHAKE_SSH_PREFIX=tsocks rake converge
The above will make all SSH invocations to all hosts be called as tsocks ssh [...]
If you want to manage your local workstation with chake, you can declare a local node using the "local" connection type, like this (in nodes.yaml):
local://thunderbolt:
itamae:
- role/workstation.rb
To apply the configuration to the local host, you can use the conventional rake converge:thunderbolt, or the special target rake local.
When converging all nodes, chake will skip nodes that are declared with the local:// connection and whose hostname does not match the hostname in the declaration. For example:
local://desktop:
itamae:
- role/workstation.rb local://laptop:
itamae:
- role/workstation.rb
When you run rake converge on desktop, laptop will be skipped, and vice-versa.
It's often useful to be able to run arbitrary commands against the data you have about nodes. You can use the Chake.nodes for that. For example, if you want to geolocate each of yours hosts:
task :geolocate do
Chake.nodes.each do |node|
puts "#{node.hostname}: %s" % `geoiplookup #{node.hostname}`.strip
end end
March 2023 |