Skip to content

Instantly share code, notes, and snippets.

@pcn
pcn / permission-shouldnt-be-denied.md
Created April 17, 2018 20:52
And now something else is weird with salt-ssh
salt-ssh -c configdir '*cron*' -i --state-output=mixed --roster-file configdir/roster state.sls clobber_minion_master
[ERROR   ] An Exception occurred while executing state.sls: [Errno 13] Permission denied: '/opt/salt/running_data/var'
cron-1:
    An Exception occurred while executing state.sls: [Errno 13] Permission denied: '/opt/salt/running_data/var'

The state itself is just a file.managed:

@pcn
pcn / salt-ssh-invocation.md
Created April 17, 2018 19:58
What is the 11th argument?

This is about as close as I can get to the documentation for the file.managed execution module.

Here is the example:

salt '*' file.manage_file \
  /etc/httpd/conf.d/httpd.conf \
  '' \
  '{}' \
  salt://http/httpd.conf \
@pcn
pcn / complex_salt_orchestrate.sls
Created March 12, 2018 15:23 — forked from whiteinge/complex_salt_orchestrate.sls
An example of a complex, multi-host Salt Orchestrate state that performs status checks as it goes
# /srv/salt/upgrade_the_app.sls
# Example of a complex, multi-host Orchestration state that performs status checks as it goes.
# Note, this is untested and is meant to serve as an example.
# Run via: salt-run state.orch upgrade_the_app pillar='{nodes: [nodeA, nodeB], version: 123}'
{% set nodes = salt.pillar.get('nodes', []) %}
{% set all_grains = salt.saltutil.runner('cache.grains',
tgt=','.join(nodes), tgt_type='list') %}
{# Default version if not given at the CLI. #}
@pcn
pcn / BUILD
Last active February 1, 2018 23:36
Something in bazel broke between 0.8.0 and 0.9.0 (and still in 0.10.0) when using distroless
package(default_visibility = ["//visibility:public"])
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
pkg_tar(
name = "dev-config",
strip_prefix = "/dev-config",
extension = "tar.gz",
srcs = glob(["dev-config/*"]),
mode = "0644",
@pcn
pcn / testfoo
Created December 6, 2017 13:20
Just testing out execution modules
ubuntu@spacey-saltmaster-vagrant:/srv/salt/modules/_modules$ cat testfoo.py; sudo salt-call testfoo.test | head
def test():
return __grains__
local:
----------
SSDs:
- xvda
biosreleasedate:
08/24/2006
biosversion:
@pcn
pcn / BUILD
Created December 4, 2017 18:33 — forked from jayeye/BUILD
stamping with build information. Obviously, replace _slash_ in the filenames with an actual slash!
package(default_visibility = ["//visibility:public"])
genrule(
name = "genpybuildinfo",
outs = [
"buildinfo.py",
],
stamp = 1,
cmd = "./$(location tools/mkpybuildinfo.sh) > \"$@\"",
tools = [
@pcn
pcn / ec2_info.py
Created July 20, 2017 20:57
Basically the same as the original ec2_info.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Get some grains information that is only available in Amazon AWS
Author: Erik Günther, J C Lawrence <claw@kanga.nu>, Mark McGuire
"""
import logging
import httplib
@pcn
pcn / pre-commit
Created May 30, 2017 18:14
git pre-commit hook for using fac
#!/bin/sh
which fac
if [ $? -eq 1 ] ; then
exit 0 ; # fac isn't installed, don't try to invoke it
fi
set -ev
fac -v
@pcn
pcn / dnsinvoke.py
Created April 13, 2017 18:45
A quick salt runner using dns
import salt.client
def geta(target='saltmaster', name=None):
lcl = salt.client.get_local_client(__opts__['conf_file'])
return lcl.cmd(target, 'dnsutil.A', [name])
@pcn
pcn / lookup_jid_time.py
Last active April 12, 2017 21:51
Looking up jids takes a lot longer than you'd think in salt
import salt.config
import salt.runner
import salt.client
import time
import cProfile
o = salt.config.client_config("/etc/salt/master")
l = salt.client.LocalClient()
rc = salt.runner.RunnerClient(o)