what's ansible & use case (by 이세웅)

44
Ansible April 22, 2017 LEE SAE WOONG

Upload: i-goo-lee

Post on 23-Jan-2018

163 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: What's Ansible & Use case (by 이세웅)

Ansible

April 22, 2017

LEE SAE WOONG

Page 2: What's Ansible & Use case (by 이세웅)

Motive

Page 4: What's Ansible & Use case (by 이세웅)

[localhost]# mkdir –p /mysql/backup [localhost]# cd /mysql/backup [localhost]# wget http://mysql/download/meb_upgrade.sh [localhost]# sh meb_upgrade.sh

Upgrade Script

Page 5: What's Ansible & Use case (by 이세웅)

MEB 3.10 MEB 3.12

UPGRADE

1000 over

Page 7: What's Ansible & Use case (by 이세웅)

[localhost]# mkdir –p /mysql/backup [localhost]# cd /mysql/backup [localhost]# wget http://mysql/download/meb_upgrade.sh [localhost]# sh meb_upgrade.sh

Deploy with bash shell

For $hostlist loop

mkdir –p /mysql/backup cd /mysql/backup

wget http://mysql/download/meb_upgrade.sh sh meb_upgrade.sh

done

Page 8: What's Ansible & Use case (by 이세웅)

[localhost]# mkdir –p /mysql/backup [localhost]# cd /mysql/backup [localhost]# wget http://mysql/download/meb_upgrade.sh

[localhost]# sh meb_upgrade.sh

Deploy with bash shell

For $hostlist loop

mkdir –p /mysql/backup cd /mysql/backup wget

wget http://mysql/download/meb_upgrade.sh sh meb_upgrade.sh

Done

More `Easy`, `comfortable`, `Safety` deploy?

Page 9: What's Ansible & Use case (by 이세웅)

Completed Basic TEST

Using Ansible

Define Deploy method

Dev Ops

TEAM

MEB 3.12

Page 10: What's Ansible & Use case (by 이세웅)

• Ansible in a Nutshell • Ansible Installation • How to use ansible? • Ansible Use Case • Demo • Ansible UI tool

Page 11: What's Ansible & Use case (by 이세웅)

Ansible in a Nutshell

Page 12: What's Ansible & Use case (by 이세웅)

Ansible in a Nutshell Launched in early 2013

October 16 2015, Redhat acquire Ansible

Simple, Agentless

Easy to manage

Idempotent (ansible module)

100% Python

Configuration management

Uses ssh

Don’t need to learn a programming language(i.e. Ruby)

http://docs.ansible.com/intro_installation.html

Page 13: What's Ansible & Use case (by 이세웅)

Ansible in a Nutshell Launched in early 2013

October 16 2015, Redhat acquire Ansible

Simple, Agentless

Easy to manage

Idempotent (ansible module)

100% Python

Configuration management

Uses ssh

Don’t need to learn a programming language(i.e. Ruby)

http://docs.ansible.com/intro_installation.html

Page 14: What's Ansible & Use case (by 이세웅)

Ansible in a Nutshell cont. Ansible is modular. 1024+ • MySQL Modules

– mysql_db Add remove databases to remote hosts

– mysql_replication Manage MySQL replication

– mysql_user MySQL user management

– mysql_variables Manage global variables

• Others Modules – Mongodb, postgresql

– Package managers (yum, apt)

– Service

– File

– Template

Page 15: What's Ansible & Use case (by 이세웅)

Ansible in a Nutshell cont.

Ansible is a very popular open source project.

- 22,519 stars and 7,374 forks on GitHub on ‘17.04.11

- Puppet : 4,414 stars, 1,825 forks

- Chef : 4,773 stars, 1,992 forks

- Fluentd : 5,127 stars, 617 forks

Page 16: What's Ansible & Use case (by 이세웅)

Ansible in a Nutshell cont.

Google Trends (i.e.https://www.google.co.kr/trends/explore#q=ansible)

> Interest over time > Regional interest

Page 17: What's Ansible & Use case (by 이세웅)

Installation

Page 18: What's Ansible & Use case (by 이세웅)

# install the epel-release RPM if needed on CentOS, RHEL, or Scientific

Linux

– Ansible Manual

$ wget --no-check-certificate https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

$ rpm -Uvh epel-release-latest-6.noarch.rpm

$ yum –y install ansible

$ ansible --version

ansible 2.2.1.0

config file = /etc/ansible/ansible.cfg

configured module search path = Default w/o overrides

http://docs.ansible.com/intro_installation.html

Page 19: What's Ansible & Use case (by 이세웅)

# Test installation case1

• Set hosts to test

$ cat /etc/ansible/ansible.cfg | grep

inventory = /etc/ansible/hosts

$ echo "127.0.0.1" > /etc/ansible/hosts

• Test your installation:

$ ansible all -m ping --connection=local

127.0.0.1 | success >> {

"changed": false,

"ping": "pong"

}

http://docs.ansible.com/ansible/playbooks_delegation.html

# Test installation case2

• Set hosts to test

$ echo "127.0.0.1" > ~/ansible_hosts

$ export ANSIBLE_HOSTS=~/ansible_hosts

• Test your installation:

$ ansible all -m ping -i ~/ansible_hosts --connection=local

127.0.0.1 | success >> {

"changed": false,

"ping": "pong"

}

Page 20: What's Ansible & Use case (by 이세웅)

How to use ansible?

Page 22: What's Ansible & Use case (by 이세웅)

• Ad-Hoc $ ansible mysql -m yum –a "name=python state=installed"

• Playbooks $ ansible-playbook pb_mysql.yml

Playbooks

---

- name: Install python

yum:

name: python

state: installed

Page 23: What's Ansible & Use case (by 이세웅)

• YAML – Read as ‘yameul[야믈]’or ’[얌]’

– Data serialized form that people can easily read

– Origin: Yet Another Markup Language

– Now: Derived from YAML ain’t Markup Language

Playbooks cont.

[ json “rdbms”, { “mysql”:[“oracle”,”enterprise”,5.6.17] } ]

- rdbms YAML - mysql

- oracle

- enterprise

- 5.6.17

Page 24: What's Ansible & Use case (by 이세웅)

---

- name: Upgrade meb 3.12

hosts: mysql

tasks:

.......

- name: Check MEB versions

command: bash -c 'rpm -qa | grep meb'

register: message

- debug: var=message.stdout_lines

.......

Playbooks cont.

Page 25: What's Ansible & Use case (by 이세웅)

$ cat tags_test.yml --- - name: Upgrade meb 3.12 hosts: mysql gather_facts: false tasks: - name: Check rpm mysql library command: bash -c 'rpm -qa | grep mysql' tags: always - name: Check rpm meb version command: bash -c 'rpm -qa | grep meb' tags: rpm_meb - name: Check rpm zlib version command: bash -c 'rpm -qa | grep zlib' tags: rpm_zlib

Tags

Page 26: What's Ansible & Use case (by 이세웅)

$ cat /etc/ansible/hosts

[mysql] MYSQLDB0001 MYSQLDB0002 MYSQLDB0003 MYSQLDB0004 MYSQLDB0005

[mongo]

MONGODB1001 MONGODB1002 MONGODB1003 MONGODB1004 MONGODB1005

Inventory & Groups

Page 27: What's Ansible & Use case (by 이세웅)

• Jinja2 is templating language for Python – my.cnf.j2

– redis.conf.j2

– mongod.conf.j2

– index.php.j2

Templates

$ vi.my.cnf.j2 [mysqld] read-only = {{ mysql_read_only|default(0) }} datadir = {{ mysql_data_dir }} tmpdir = {{ mysql_tmp_dir }} pid-file = {{ mysql_logs_dir }}/mysqld.pid socket = /tmp/mysql.sock skip-name-resolve character-set-server = utf8 collation-server = utf8_general_ci

Page 28: What's Ansible & Use case (by 이세웅)

# cat mysql/vars.yml

mysql_daemon: mysql

mysql_conf_path: /dbpart/rexhome/my.cnf

mysql_homedir: /dbpart/rexhome

mysql_datadir: /dbpart/rexhome/data

mysql_socket:/dbpart/rexhome/tmp/mysqld.sock

mysql_log: /dbpart/rexhome/log

mysql_pid: /dbpart/rexhome/log/mysqld.pid

Variables

Page 29: What's Ansible & Use case (by 이세웅)

# In playbook:

- set_fact:

buffer_pool_size: "{{ (ansible_memtotal_mb * 0.6) | int }}"

# In my.cnf.j2 (template):

innodb-buffer-pool-size = {{ buffer_pool_size | int }}

Facts

Page 30: What's Ansible & Use case (by 이세웅)

mysql/tasks mysql/tasks/monitoring.yml mysql/tasks/backups.yml mysql/tasks/server.yml mysql/tasks/main.yml mysql/tasks/base.yml mysql/templates mysql/templates/5.7 mysql/templates/5.7/my.cnf.j2 mysql/templates/5.6 mysql/templates/5.6/my.cnf.j2 mysql/vars mysql/vars/main.yml mysql/files mysql/files/etc_init.d_mysql

Roles

Page 31: What's Ansible & Use case (by 이세웅)

Ansible Use Case

Page 32: What's Ansible & Use case (by 이세웅)

What can I use Ansible to Do?

Configure managemnet

mysql variables, user, schema …

OS crontab, /etc/init.d, variables …

Install server

mysql, redis, mongodb server …

Install AWS EC2 Instance

Application Deployment

source, file …

Page 33: What's Ansible & Use case (by 이세웅)

LINE Ansible Use Case MEB upgrade

: 1000+ 2016.05.17

MEM 2.3 fadeout : 1000+

2017.03.16

DB ACL : 1000+

2017.02.24

MySQL install & Deploy tool

DB DDL : 4096 database

2017.03.10

2017.01.16

Page 34: What's Ansible & Use case (by 이세웅)

Demo

• Install Yum file

• MySQL create database

• MySQL add user

• MySQL variables

• MySQL root user password

https://github.com/saewoong/ansible_sample/blob/master/pb_mysql.yml

Page 35: What's Ansible & Use case (by 이세웅)

$ cat pb_mysql.yml --- - name: Set MySQL with modules hosts: mysql gather_facts: no vars: MySQL_root_user: root MySQL_root_pass: test MySQL_port: 3306 tasks: - name: install MySQL-python and python-simplejson yum: name: "{{ item }}" state: installed with_items: - MySQL-python - python-simplejson tags: yum - name: MySQL create database mysql_db: name=ansible_rex state=present login_user="{{ MySQL_root_user }}" login_password="{{ MySQL_root_pass }}" login_host="{{ inventory_hostname }}" login_port="{{ MySQL_port }}" tags: database

- name: MySQL user add_drop mysql_user: name=federer password=test state=present priv=*.*:ALL login_user="{{ MySQL_root_user }}" login_password="{{ MySQL_root_pass }}" login_host="{{ inventory_hostname }}" login_port="{{ MySQL_port }}" tags: add_user - name: MySQL variables mysql_variables: variable=max_connections value=3000 login_user=root login_password="{{ MySQL_root_pass }}" login_host="{{ inventory_hostname }}" login_port="{{ MySQL_port }}" tags: variables - name: Change MySQL root user password mysql_user: name="{{ MySQL_root_user }}" state=present password=rex host="{{ item }}" login_user=root login_password="{{ MySQL_root_pass }}" login_host="{{ inventory_hostname }}" login_port="{{ MySQL_port }}" with_items: - localhost tags: change_root

Page 36: What's Ansible & Use case (by 이세웅)

DEMO https://github.com/saewoong/ansible_sample/blob/master/pb_mysql.yml

Page 37: What's Ansible & Use case (by 이세웅)

Ansible UI Tool

Page 39: What's Ansible & Use case (by 이세웅)

Ansible Tower (Automation Framework)

Page 43: What's Ansible & Use case (by 이세웅)

Question?

( We are hiring )