Skip to content

Instantly share code, notes, and snippets.

View maprangzth's full-sized avatar

Komsan Kamsamur maprangzth

View GitHub Profile
@maprangzth
maprangzth / learning-ansible-ep.05_playbooks.md
Last active January 23, 2024 04:27
Ansible พื้นฐานที่ (ตัวเอง) ควรรู้ Ep.05 — Playbooks

Ansible พื้นฐานที่ (ตัวเอง) ควรรู้ Ep.05 - Playbooks

Ansible Logo

จาก Ep. ก่อนหน้านี้ที่พูดเกี่ยวกับการใช้งาน Ansible แบบ Ad-Hoc Commands ก็คงพอที่จะทำให้เห็นประโยชน์การนำ Ansible มาใช้งานกันแล้วคร่าวๆ แต่...จะเห็นได้ว่าการเรียกใช้งาน Module บางตัวนั้นจะต้องระบุ Opstions เยอะแยะมากมายวุ่นวายไปหมด ยิ่งไปกว่านั้นสมมุติถ้าเรามี Task ที่ต้องทำหลายๆ Tasks ยกตัวอย่าง เช่น ติดตั้ง Web Server, คอนฟิก Web Server, ติดตั้ง Database Server ทำ Hardening ฯลฯ คำถามคือ...เราต้องมานั่งพิมพ์คำสั่งยาวๆ ทีละ Task งั้นรึ? ดูมันวุ่นวายเนอะ -_-

Ansible จึงมีวิธีจัดการกับเรื่องยุ่งยากซับซ้อนจากที่ต้องรัน Manual แต่ละ Task ก็เกิดวิธีการเขียนเป็น Ansible Script และมีชื่อเรียกอย่างเป็นทางการว่า Playbooks ซึ่งในหัวข้อนี้เราก็จะดูกันว่ามันคืออะไร? และจะมาช่วยให้มันง่ายขึ้นกว่าการใช้งานแบบ Ad-Hoc Commands จริงๆ หรือเปล่า? ชักช้าอยู่ใยไปเริ่มกันเลยดีกว่าครับ

Playbooks คืออะไร?

Playbooks คือ **Configuratio

@maprangzth
maprangzth / sysctl.conf
Created October 12, 2018 04:48 — forked from yegorg/sysctl.conf
ubuntu sysctl performance tuning
# Kernel sysctl configuration file for Linux
#
# Version 1.12 - 2015-09-30
# Michiel Klaver - IT Professional
# http://klaver.it/linux/ for the latest version - http://klaver.it/bsd/ for a BSD variant
#
# This file should be saved as /etc/sysctl.conf and can be activated using the command:
# sysctl -e -p /etc/sysctl.conf
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and sysctl.conf(5) for more details.
@maprangzth
maprangzth / sed cheatsheet
Created October 19, 2020 04:54 — forked from asenchi/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@maprangzth
maprangzth / iptables
Created November 28, 2017 13:27 — forked from m4ce/iptables
Transparent proxy with Squid and IPTables
# Rules for transparent proxying
iptables -N NO_PROXY -t nat
iptables -A NO_PROXY -t nat -d 0.0.0.0/8 -j ACCEPT
iptables -A NO_PROXY -t nat -d 10.0.0.0/8 -j ACCEPT
iptables -A NO_PROXY -t nat -d 127.0.0.0/8 -j ACCEPT
iptables -A NO_PROXY -t nat -d 169.254.0.0/16 -j ACCEPT
iptables -A NO_PROXY -t nat -d 172.16.0.0/12 -j ACCEPT
iptables -A NO_PROXY -t nat -d 192.168.0.0/16 -j ACCEPT
iptables -A NO_PROXY -t nat -d 224.0.0.0/4 -j ACCEPT
iptables -A NO_PROXY -t nat -d 240.0.0.0/4 -j ACCEPT
@maprangzth
maprangzth / hosts.json
Created February 24, 2018 17:04
Ansible Inventory File JSON Format
{
"centos": {
"hosts": {
"centos1": {
"ansible_port": 2222
},
"centos2": null,
"centos3": null
},
"vars": {
@maprangzth
maprangzth / vip-with-keepalived.md
Last active November 2, 2022 14:58
VIP for Elasticsearch and Logstash with Keepalived

VIP for Elasticsearch and Logstash with Keepalived

Step 1: Install keepalived

# yum -y install keepalived
# chkconfig keepalived on
@maprangzth
maprangzth / Exception.rb
Created October 28, 2022 13:37 — forked from stuart-warren/Exception.rb
Windows Event log via nxlog (json) -> logstash 1.2 config
Exception in filterworker {"exception"=>#<NoMethodError: undefined method `[]=' for nil:NilClass>, "backtrace"=>["file:/opt/logstash/logstash.jar!/logstash/event.rb:135:in `[]='", "org/jruby/RubyProc.java:255:in `call'", "(eval):9:in `exec'", "org/jruby/RubyProc.java:255:in `call'", "file:/opt/logstash/logstash.jar!/logstash/util/fieldreference.rb:44:in `exec'", "file:/opt/logstash/logstash.jar!/logstash/event.rb:134:in `[]='", "file:/opt/logstash/logstash.jar!/logstash/filters/mutate.rb:234:in `rename'", "org/jruby/RubyHash.java:1332:in `each'", "file:/opt/logstash/logstash.jar!/logstash/filters/mutate.rb:232:in `rename'", "file:/opt/logstash/logstash.jar!/logstash/filters/mutate.rb:205:in `filter'", "(eval):127:in `initialize'", "org/jruby/RubyProc.java:255:in `call'", "file:/opt/logstash/logstash.jar!/logstash/pipeline.rb:243:in `filter'", "file:/opt/logstash/logstash.jar!/logstash/pipeline.rb:191:in `filterworker'", "file:/opt/logstash/logstash.jar!/logstash/pipeline.rb:134:in `start_filters'"], :level=>:

Ansible พื้นฐานที่ (ตัวเอง) ควรรู้ Ep.01 - What's Ansible?

Ansible Logo

เกริ่นนำกันซักหน่อย

ที่มาที่ไปก็คือ เสาร์-อาทิตย์ ว่างจัด จริงๆ ก็พยายามทำให้ตัวเองไม่ว่างนั่นแหละ คือนั่งอ่านหนังสือหรืออ่านบทความที่คนอื่นเขาเขียน แต่ก็อย่างว่าแค่นั่งอ่าน 555+ อ่านจบแล้วทำไรล่ะ เบื่อ...นั่งแดรกกเบียร์แม่มมม (กิจกรรมหลักของผมเลยก็ว่าได้) แต่ไม่กี่วันที่ผ่านมารัฐบาลเสือกขึ้นภาษีอีก ร้องเฮ้ดังมากกกก จะให้ทำแบบเมื่อก่อนคงไม่ได้ ก็เลยสะพายเป้ใส่โน๊ตบุคไปนั่งร้านกาแฟสั่งชาเขียวเย็นๆ อ่านหนังสือชิวๆ แอร์ก็พร้อม สาวๆ ก็มีให้มองคงไม่มีอะไรดีไปกว่านี้อีกแล้วววว บวกกับเราเองก็สนใจตัว Ansible ด้วยอยู่แล้ว และที่สำคัญ Infrastructure as Code เป็นสิ่งที่ควรค่าแก่การศึกษา เพราะ System Admin Thailand 4.0 เขาไม่มานั่ง Setup Infrastructure แบบวิถีดั้งเดิมกันแล้ว ปั๊ดโถ๊ว!!! (เสียงและสีหน้าลุงตู่ตอนตอบคำถามนักข่าว)

Ansible คืออะไร?

Ansible is a radically simple IT automation engine that automates clo
@maprangzth
maprangzth / kafka-oracle-vm-config.md
Created September 21, 2022 03:27 — forked from dyoung522/kafka-oracle-vm-config.md
kafka installation with systemd
  1. Install Kafka

    cd /opt
    curl -O http://www.gtlib.gatech.edu/pub/apache/kafka/0.11.0.0/kafka_2.11-0.11.0.0.tgz
    tar xvzf kafka_2.11-0.11.0.0.tgz
    ln -s kafka_2.11-0.11.0.0/ kafka
  2. Edit /usr/lib/systemd/system/kafka-zookeeper.service

@maprangzth
maprangzth / docker-compose.yml
Created June 10, 2022 02:13 — forked from j-tim/docker-compose.yml
Elasticsearch 7.x Single Cluster Node for local development including Kibana
version: '3.7'
services:
# Elasticsearch Docker Images: https://www.docker.elastic.co/
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.0
container_name: elasticsearch
environment:
- xpack.security.enabled=false