A few assumptions with these states and modules:
- Running rancher server 1.6.x
- rancher-cli is installed on your salt-master and available globally (usr/local/bin)
- Some stuff is hardcoded to how we have our salt and pillar paths setup (e.g. /srv/salt , /srv/pillar). You’ll need to adjust paths for how you have it configured
Right now you can make three calls with this module: list, new stack, and upgrade services
The module is essentially a wrapper for the rancher-cli which needs to be installed on the salt master.
Create a directory called _modules
in your salt files root and copy the python script over
Run sudo salt-call saltutil.sync_modules
to install it. You should get a return like this:
local:
- modules.rancher
sudo salt-call rancher.containers
This will list all running containers in your rancher environment
(similar to docker ps -a
)
The rancher.stack
does 2 things:
- Creates a new stack in rancher
- Upgrades the whole stack of containers (probably don’t want to do regularly)
Create a new stack, named website
, running 1 container of apache, 1 nginx:
sudo salt-call rancher.stack sample-website
To upgrade the entire stack:
sudo salt-call rancher.stack website upgrade
To confirm or rollback (separate commands from upgrade):
sudo salt-call rancher.stack website upgrade confirm/rollback
To upgrade a single container/service, use rancher.upgrade
. The commands are similar to the stack commands
To upgrade only the nginx container in the stack website
sudo salt-call rancher.upgrade website nginx
To confirm or rollback (separate command):
sudo salt-call rancher.upgrade website nginx confirm/rollback
NOTE: the upgrade tag will default to :latest
unless specified when calling the upgrade. Like so:
sudo salt-call rancher.upgrade website nginx 1.12
This can be helpful when trying to control versioning in critical environments without needing to change the docker-compose.yml everytime.
Just change the tag to the variable {{ config.tag }}
for it to be mapped.
This module allows environment variables to be passed through to the rancher config. The module imports the .sls as config
. You then call that in your docker-compose.yml
as config.entry
. See the sample-website files for an example.
This module as-is used the pillar file associated with the "environment" we have configured (like, lab, staging, etc.), with this salt-call open('/srv/pillar/%s.sls') % __salt__['grains.get']['environment'])
, however you can change this to whatever pillar file or grain.