Skip to content

Instantly share code, notes, and snippets.

@rjsalts
rjsalts / distribute.j2
Last active January 3, 2016 07:39
Equally divide servers to backends in ansible template
{% for host in groups['systems-server'] %}
{% if host == ansible_fqdn %}
{% set target_sysdb = loop.index0 % groups['sysdb-server']|length()|int() %}
{{ groups['sysdb-server'][target_sysdb] }}
{% endif %}
{% endfor %}
@rjsalts
rjsalts / discover_checkmk.yml
Created January 16, 2014 00:38
Ansible playbook to discover all the hosts which have the check_mk agent setup.
- hosts: all
vars:
- monitoring_agent : "nrpe_server"
tasks:
- name: test check_mk
local_action: wait_for port=6556 timeout=2 host={{inventory_hostname}}
register: check_mk
ignore_errors: True
- name: set fact
set_fact: monitoring_agent="check_mk_agent"
#!/usr/bin/php
<?php
$fdspec = array(
0 => array( "pipe", "r" ),
1 => array( "pipe", "w" ),
2 => array( "pipe", "w" ),
);
$proc = proc_open("ls",$fdspec,$pipes,NULL,array());
if (is_resource($proc)) {
fclose($pipes[0]);
options {
...
};
view "one" {
match-clients {
key "key_one";
!key "key_two";
!key "key_three";
...
!key "key_n";
define loadkmod {
exec { "modprobe_$name":
command => "/sbin/modprobe ${name}",
unless => "/bin/grep \"^${name} \" /proc/modules",
}
exec { "add_${name}_to_etc_modules" :
command => "/bin/bash -c 'echo $name >> /etc/modules'",
unless => "/bin/grep ^${name} /etc/modules",
}
class lightdm ($lightdmconf = { SeatDefaults => { user-session => "ubuntu", greeter-session => "unity-greeter", greeter-show-manual-login => "true", greeter-hide-users => "true" } } ) {
file { '/etc/lightdm/lightdm.conf':
ensure => present,
mode => 644,
owner => root,
group => root,
content => template('lightdm/lightdm.conf.erb'),
}
}
#!/bin/bash
# Analyze log file and send result to zabbix.
# Usage: bash analog_send.sh /path/to/analog.ini /path/to/nginx/access.log
HOST=$1 # name of host in Zabbix frontend, *not* IP or hostname!
ARGS_FILE=$2
LOG_FILE=$3
LOG_NAME=$(basename $LOG_FILE)
dscl localhost -readall /LDAPv3/ldap.example.com/Automount
dsAttrTypeNative:objectClass: automount top
AppleMetaNodeLocation: /LDAPv3/ldap.example.com
AppleMetaRecordName: cn=/,ou=auto.shares.it,ou=autofs,dc=example,dc=com
AutomountInformation:
-fstype=nfs,nfsvers=4,rw,fsc,hard,intr,nodev,noexec,nosuid,rsize=81920,wsize=81920 nfs.example.com:/vol/volShareShares/departments/it
MetaAutomountMap: auto.shares.it
RecordName: /
RecordType: dsRecTypeStandard:Automount
-
# Locale, country and keyboard settings
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i console-setup/modelcode string pc105
d-i console-setup/variant USA
d-i console-setup/layout USA
d-i console-setup/layoutcode string us
# Network configuration
d-i netcfg/choose_interface select auto
define lxchost::mountContainerMounts {
$mntarr = split($title, ':')
$mntpoint = $mntarr[-1]
$classname = downcase(regsubst($mntpoint,'^.*/','lxchost::implementation::mount'))
require $classname
}