Skip to content

Instantly share code, notes, and snippets.

View maprangzth's full-sized avatar

Komsan Kamsamur maprangzth

View GitHub Profile

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

Ansible Logo

ในการใช้งาน Ansible หลักๆ จะมีอยู่ Command-line ให้ใช้งานอยู่สองแบบ คือ

  1. /usr/bin/ansible
  2. /usr/bin/ansible-playbook

ซึ่งใน Ep. นี้เรามาโฟกัสกันที่ /usr/bin/ansible กันก่อน ส่วน /usr/bin/ansible-playbook คืออะไรเดี๋ยวจะมาว่ากันใน Ep. ถัดไป

@maprangzth
maprangzth / create_ansible_user.yml
Created October 22, 2017 06:32
Simple Playbooks for Create User
---
- name: Create Ansible user
hosts: all
remote_user: root
vars:
user_name: maprangzth
user_keys: https://github.com/maprangzth.keys
tasks:
- name: Ensure ansible user exists
user:
@maprangzth
maprangzth / install_apache.yml
Created October 22, 2017 08:38
Simple Playbooks for Install Apache Web Server
---
- name: Install Apache Web Server
hosts: web-server
remote_user: maprangzth
tasks:
- name: Ensure httpd package is latest
yum:
name: httpd
state: latest
notify: Start and enabled httpd service
@maprangzth
maprangzth / install_reqiured_package.yml
Created October 22, 2017 08:39
Simple Playbooks for Explanation About Loop
---
- name: Install reqiured packages
hosts: all
remote_user: maprangzth
tasks:
- name: Ensure EPEL Repo is present
yum:
name: epel-release
state: present
become: True
@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 November 3, 2017 07:12 — forked from sokratisg/sysctl.conf
Tuned sysctl.conf for use by CentOS/RHEL 6.x or later
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Turn on execshield
# 0 completely disables ExecShield and Address Space Layout Randomization
# 1 enables them ONLY if the application bits for these protections are set to “enable”
# 2 enables them by default, except if the application bits are set to “disable”
# 3 enables them always, whatever the application bits
@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 / 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 / Ansible-Inventory-File-YAML-JSON.md
Last active February 25, 2018 04:03
มาลองเขียน Ansible Inventory File ให้อยู่ในรูปแบบ YAML/JSON กันเถอะ

Ansible Logo

สำหรับท่านที่ศึกษาและใช้งาน Ansible ก็คงจะรู้จักและคุ้นเคยกับ INI Inventory file กันเป็นอย่างดีอยู่แล้ว หน้าตามันก็จะประมาณนี้:

[centos]
centos1 ansible_port=2222
centos[2:3]

[centos:vars]