Skip to content

Instantly share code, notes, and snippets.

View maxim's full-sized avatar
🛠️

Max Chernyak maxim

🛠️
View GitHub Profile
@maxim
maxim / tasks.yml
Last active June 15, 2016 03:41
Copy file on remote machine in ansible
- name: ensure file exists at path
shell: rsync -ci /source/path /destination/path
register: rsync_result
changed_when: "rsync_result.stdout != ''"
# Permissions cheatsheet
`chmod [a]bcd`
* bit a — sticky:1/setgid:2/setuid:4 (optional, default: 0)
* bit b — owner | x:1/w:2/r:4 - xw:3/xr:5/wr:6/xwr:7
* bit c — group | x:1/w:2/r:4 - xw:3/xr:5/wr:6/xwr:7
* bit d — everyone | x:1/w:2/r:4 - xw:3/xr:5/wr:6/xwr:7
note: only file/dir owner can chmod it
def authorize_key_for_root(config, *key_paths)
[*key_paths, nil].each do |key_path|
if key_path.nil?
fail "Public key not found at following paths: #{key_paths.join(', ')}"
end
full_key_path = File.expand_path(key_path)
if File.exists?(full_key_path)
config.vm.provision 'file',
@maxim
maxim / task.yml
Created June 12, 2014 11:09
Adding github to known_hosts with ansible
- name: ensure github.com is a known host
lineinfile:
dest: /root/.ssh/known_hosts
create: yes
state: present
line: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
regexp: "^github\\.com"
@maxim
maxim / task.yml
Created June 10, 2014 18:11
ansible task for ensuring postgresql extension exists without skipping or perpetual "changed"
- name: ensure postgresql hstore extension is created
sudo: yes
sudo_user: postgres
shell: "psql {{ postgresql_database }} -c 'CREATE EXTENSION hstore;'"
register: psql_result
failed_when: >
psql_result.rc != 0 and ("already exists" not in psql_result.stderr)
changed_when: "psql_result.rc == 0"

Upon launch of custom base box intended as app behind load balancer:

  1. [serf] join cluster, update lists
  2. update local iptables
  3. [serf] announce presence (already part of step 1?)
  4. provision self (chef/ansible/docker/etc)
  5. pull app (deploy to self from git, deb, docker, could be part of step 4?)
  6. [serf] announce online
Problem AWS DigitalOcean
Network isolation Private Cloud/Security Groups tinc / n2n / freelan
Node initialization CloudInit/User Data ?
Node discovery EC2 API Serf
Pull app on scale More Like This Serf
Distributed config etcd etcd
@maxim
maxim / weird.rb
Last active August 29, 2015 13:57
class Foo
alias_method :bar,
def foo
:hello
end
end
Foo.new.bar # => :hello
@maxim
maxim / barney.rb
Last active December 29, 2015 11:59
Use case for refinements
module Barney
refine String do
def wait_for_it(ending)
replace(self + ending)
end
end
end
using Barney
"legen".wait_for_it "dary" # => "legendary"
@maxim
maxim / gist:6981675
Last active December 25, 2015 13:09
echo "девуш\xD0:" | selecta
/Users/max/Executables/selecta:124:in `=~': invalid byte sequence in UTF-8 (ArgumentError)
from /Users/max/Executables/selecta:124:in `block in matches'
from /Users/max/Executables/selecta:124:in `select'
from /Users/max/Executables/selecta:124:in `matches'
from /Users/max/Executables/selecta:144:in `render'
from /Users/max/Executables/selecta:134:in `render!'
from /Users/max/Executables/selecta:37:in `block in main'
from /Users/max/Executables/selecta:169:in `block in with_screen'