Kick Start Ansible
Kick Start Ansible
sdmoko@sdmoko.net
Apasih Ansible?
Apasih Ansible?
Platform otomatisasi
●
Otomatisasi yang mudah dibaca
●
Tidak memerlukan skill khusus untuk coding
●
Menjalankan tugas secara berurutan
●
Membuat kita lebih produktif
Ansible itu Mantap
●
Apllication Deployment
●
Configuration Management
●
Workflow Orchestration
●
Orchestrate the application lifecycle
Ansible itu Agentless
●
Agentless Architecture
●
Menggunakan OpenSSH & WinRM
●
Tidak ada agents untuk exploit atau update
●
Lebih efisien & lebih aman
Ansible itu Cross Platfrom
# Ubuntu, Debian
$ sudo apt install ansible
Bagaimana Ansible bekerja
Modules
●
Apt/yum ●
Template
●
Copy ●
User
●
File ●
Mysql
●
Git ●
Uri
●
Ping ●
Assert
●
Service ●
Debug
Ad-Hoc Commands
AdHoc Commands
# Cek koneksi semua server yang siap dimanage
$ ansible all -m ping
],
"ansible_architecture": "x86_64",
"ansible_bios_date": "12/01/2014",
Inventory
[webservers]
alpha.example.org
beta.example.org
192.168.1.100
192.168.1.110
[all:vars]
ansible_user=vagrant
Pengenalan Playbooks & Demo
Variabel
handlers:
- name: restart nginx
action: service name=nginx state=restarted enabled=yes
Plays & Playbooks
tasks:
- name: update apt cache
apt: update_cache=yes cache_valid_time=3600
handlers:
- name: restart nginx
action: service name=nginx state=restarted enabled=yes
Menjalankan Playbooks
# site.yml
---
hosts: webservers
roles:
- common
- web
Membuat struktur Roles dengan Ansible-Galaxy
$ ansible-galaxy init namaroles1
$ ansible-galaxy init namaroles2
Memecah Playbooks menjadi Roles
Contoh Playbooks
- name: install and restarted nginx
hosts: webserver
remote_user: vagrant
tasks:
- name: update apt cache
apt: update_cache=yes cache_valid_time=3600
handlers:
- name: restart nginx
action: service name=nginx state=restarted enabled=yes
Struktur Roles
site.yml
roles/
web/
files/
templates/
tasks/
handlers/
vars/
defaults/
meta/
Tasks dalam Roles
# main.yml in tasks directory
---
- name: update apt cache
apt: update_cache=yes cache_valid_time=3600
roles:
- web
Markiprek
Mari Kita Ngoprek