Skip to content

Instantly share code, notes, and snippets.

View ryan-lane's full-sized avatar

Ryan Lane ryan-lane

  • PayPay Japan
  • San Francisco
View GitHub Profile
docker-registries:
https://myregistry.example.com/v1/:
email: [email protected]
password: mypassword
username: my-username
docker.url: 'tcp://127.0.0.1:2375'
Make the directory:
file.directory:
- name: /tmp/mydir
Manage the directory:
file.managed:
- name: /tmp/mydir
- source: salt://blah
- recurse: True
@ryan-lane
ryan-lane / example.md
Last active August 29, 2015 14:06
How exceptions behave in SaltStack execution modules through states and the CLI

modules/modules/testme.py:

from salt.exceptions import CommandExecutionError

def testme(name):
    if name == 'fail':
        raise CommandExecutionError('test error message')
    else:
        return True
Ensure my virtualenv is installed:
virtualenv.installed:
- name: /srv/myvenv
Run a command:
cmd.run:
- name: mycommand
Ensure my file is installed:
file.managed:
Ensure salt virtualenv exists:
virtualenv.managed:
- name: /srv/salt/venv
# Switch to the existing salt venv
- pip_exists_action: s
- system_site_packages: True
- requirements: /my/requirements.txt
Ensure modules and grains are refreshed if salt venv changes:
module.wait:
base:
'*':
- base
- service-common
- order: 1
{% for root in opts['pillar_roots']['base'] -%}
{% set service_group_sls = '{0}/{1}.sls'.format(root, grains['service_group']) -%}
{% if salt['file.file_exists'](service_group_sls) %}
'service_group:{{ grains["service_group"] }}':
- match: grain
@ryan-lane
ryan-lane / gist:e3f3bd08b75942107e52
Last active August 29, 2015 14:04
Load pillar files in the top file based on the grain
base:
# For each directory that can have pillar files
{% for root in opts['pillar_roots']['base'] -%}
# Set a variable to the path to check
{% set mygrain_sls = '{0}/{1}.sls'.format(root, grains['mygrain']) -%}
# Check to see if the file exists, if so, include that pillar file.
{% if salt['file.file_exists'](mygrain_sls) %}
'service_group:{{ grains["mygrain"] }}':
- match: grain
- {{ grains['mygrain'] }}
@ryan-lane
ryan-lane / .bashrc
Created July 15, 2014 17:26
No more pyflakes errors for salt dunders
export PYFLAKES_BUILTINS="__salt__,__opts__,__grains__,__pillars__,__context__"
@ryan-lane
ryan-lane / Vagrantfile
Created July 11, 2014 00:18
Salt development Vagrantfile
$script = <<SCRIPT
# Install salt dependencies
sudo apt-get -y update
sudo apt-get install -y build-essential libssl-dev python-dev python-m2crypto \
python-pip python-virtualenv python-zmq swig virtualenvwrapper git-core python-apt
if [ ! -d /srv/salt/venv ]
then
sudo mkdir -p /srv/salt/venv
fi
KeyError: 'file_|-Ensure statsd supervisor configuration exists_|-/etc/supervisor/conf.d/statsd.conf_|-managed'
Traceback (most recent call last):
File "/usr/bin/salt-call", line 11, in <module>
salt_call()
File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 128, in salt_call
client.run()
File "/usr/lib/python2.7/dist-packages/salt/cli/__init__.py", line 398, in run
caller.run()
File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 186, in run
ret = self.call()