Skip to content

Instantly share code, notes, and snippets.

@krdlab
krdlab / match.yml
Created November 9, 2020 10:09
Ansible の selectattr で正規表現を使う
- hosts: localhost
gather_facts: false
vars:
targets:
- instance_id: 1
instance_type: r4.large
- instance_id: 2
instance_type: r5.large
@krdlab
krdlab / wait.yml
Created August 13, 2020 05:10
Ansible を使ってリモートホスト上に指定のファイルが生成されるまで待つ
- hosts: targets
become: yes
tasks:
- name: Get UTC date
command: date -u '+%Y-%m-%d'
check_mode: no
changed_when: no
register: utc_date
- debug:
{
"id": "...",
"version": "1.0",
"type": "",
"type.version": "1.05",
"data": {
}
}
@krdlab
krdlab / each_slice.py
Last active February 22, 2019 08:52
Python のリストを N 個の塊に分割する
# もっと簡単にできないかな?
import math
N = 10
arr = [1] * 22
parts = [arr[(i*N):((i+1)*N)] for i in range(0, int(math.ceil(len(arr)/float(N))))]
for part in parts:
print(part)
@krdlab
krdlab / s3.py
Last active December 25, 2018 06:31
Python boto3 の S3 Client サンプル
import boto3
from botocore.exceptions import ClientError
client = boto3.client('s3')
try:
client.get_bucket_cors(Bucket='unknown-bucket')
except ClientError as e:
print e
@krdlab
krdlab / disable-all-jobs.groovy
Created December 10, 2018 10:39
Jenkins のジョブを一括で無効化する
jenkins.model.Jenkins.instance.items.each {
println "\nJob: ${it.name}"
it.disabled = true
}
# encoding: utf-8
class CyclicBarrier
def initialize(n)
@n = n
@await_count = 0
@mutex = Mutex.new
@var = ConditionVariable.new
end
@krdlab
krdlab / simplefile.py
Last active May 27, 2018 14:21
Ansible モジュールのサンプル (check mode & diff 対応済)
import os
from tempfile import gettempdir
from ansible.module_utils.basic import AnsibleModule
class BasicFile(object):
def __init__(self, path):
self.path = path
def exists(self):
return os.path.exists(self.path)
@krdlab
krdlab / tmpfile.py
Created May 22, 2018 19:11
Ansible モジュールのサンプル (check mode と diff 無しバージョン)
import os
from tempfile import gettempdir
from ansible.module_utils.basic import AnsibleModule
def read(path):
with open(path, 'r') as f:
return f.read()
def write(path, text):
@krdlab
krdlab / .eslintrc.json
Created May 19, 2018 02:50
Visual Studio Code で JavaScript の async/await を使う場合の設定
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2017
},
"rules": {