ansible 社内お勉強会資料
DESCRIPTION
はじめてのAnsible、触りから少し飛ばしてGalaxyTRANSCRIPT
![Page 1: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/1.jpg)
いまどきCMツール入れてなかったので“Ansible”はじめました
makoto uehara
![Page 2: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/2.jpg)
Whats Ansible ?
・構成管理 (CM: Configuration Management)ツール
・オーケストレーションツール
![Page 3: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/3.jpg)
ライバル
![Page 4: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/4.jpg)
ライバル
![Page 5: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/5.jpg)
名前の由来
「ゲド戦記」の作家さんのSF作品の中で、”アンシブル”という超高速通信を行う機械が登場する
それが由来らしい
![Page 6: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/6.jpg)
特徴
・冪等性:何回やっても同じ
・シンプル:プッシュ型でクライアントにエージェントは必要なし、python2.4以上が入っていてSSHできればOK。AnsibleはSSHのラッパー
・YAMLで書くプレイブック(構成ファイル。Cookbookみたいの)
![Page 7: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/7.jpg)
特徴
・冪等性:何回やっても同じ
・シンプル:プッシュ型でクライアントにエージェントは必要なし、python2.4以上が入っていてSSHできればOK。AnsibleはSSHのラッパー
・YAMLで書くプレイブック(構成ファイル。Cookbookみたいの)
![Page 8: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/8.jpg)
冪等性って
例えば
「ビール4本」を繰り返し注文する…
![Page 9: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/9.jpg)
冪等性がないと
oh!
![Page 10: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/10.jpg)
冪等性があると
何度やっても同じ構成に収束する
![Page 11: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/11.jpg)
構成が同じサーバーを一定に簡単に増やす
![Page 12: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/12.jpg)
特徴
・冪等性:何回やっても同じ
・シンプル:プッシュ型でクライアントにエージェントは必要なし、python2.4以上が入っていてSSHできればOK。AnsibleはSSHのラッパー
・YAMLで書くプレイブック(構成ファイル。Cookbookみたいの)
![Page 13: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/13.jpg)
Ansibleはシンプル
・エージェントレス(プッシュ型)
・SSHできればOK
・インストールもyumで一撃
rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/epel.repo
yum install --enablerepo=epel ansible
・Inventoryファイルという対象ホストを書けばすぐ使えるあとはplaybookを書くだけ
![Page 14: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/14.jpg)
Ansibleはシンプル
5つの”S”
Simply Clear (分かりやすい)
Simply Fast (習得もインストールも早い)
Simply Complete (全部を揃えているからすぐに使える)
Simply Efficient (sshは効率的)
Simply Secure (sshは安全)
![Page 15: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/15.jpg)
Chefをディする
役割いっぱい ミドルいっぱい
RabbitMQ
postgresql
Solr
Bookshelf
ChefServer
nginx
レシピはRubyで書くので学習コストいっぱい
![Page 16: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/16.jpg)
特徴
・冪等性:何回やっても同じ
・シンプル:プッシュ型でクライアントにエージェントは必要なし、python2.4以上が入っていてSSHできればOK。AnsibleはSSHのラッパー
・YAMLで書くプレイブック(構成ファイル。Cookbookみたいの)
![Page 17: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/17.jpg)
Playbook example[root@ansiblesvr001 playbook]# cat roles/hogecommon/tasks/hogehoge.yml
## Set /etc/sysctl.conf
- name: lineinfile sysctl.conf
sysctl: name="net.ipv4.ip_local_port_range" value=" 1024 65000" reload=yes state=present
### source install from Ansible Playbooks
- name: hogeuser user add
user: name=hogeuser shell=/bin/bash uid=999 group=hogewheel state=present
update_password=always password=hogehoge
## make directory
- name: directory make fox
file: path=/var/service/{{ item }} state=directory owner=hogeuser group=fox mode=0775
with_items:
- log
- data
## pkg download
- name: pkgs download
get_url: url={{ pkgurl }}/{{ servicename }}/{{ http_pkg }} dest=/usr/local/src/archive
誰でもなんとなく読める!
![Page 18: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/18.jpg)
いいところ
・冪等性ある・ドライランある・モジュールたくさんある(モジュールの単位で冪等性があり一連の処理をまとめてる)
・一気に実行させずにステップ実行できる・分岐処理ある(httpd.confをサーバーによって分けれる)
・forkオプションで並列実行可能・serialでサーバー順次実行でローリングアップデート可能・情報沢山(ちょっとやってみたネタが多いけど・・)・開発活発
![Page 19: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/19.jpg)
モジュール一例
![Page 20: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/20.jpg)
Ansible Galaxy!
Aerospikeの構築ロール書いてAnsible-Galaxyに登録してみた
これ↓
![Page 21: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/21.jpg)
Ansible Galaxy!
①ロールに対してansible-galaxy initを実行してメタデータを作る[root@ansiblesvr001 ~]# ansible-galaxy init aerospike/
The directory ./aerospike/ already exists.
You can use --force to re-initialize this directory,
however it will reset any main.yml files that may have
been modified there already.
怒られたので—force した↓そのあとgit push。[root@ansiblesvr001 ~]# ansible-galaxy init --force aerospike/
aerospike/ was created successfully
② README.mdとmetaが出来てる[root@ansiblesvr001 ~]# ll aerospike/
合計 32
-rw-r--r-- 1 root root 1328 11月 26 08:54 2014 README.md
drwxr-xr-x 2 root root 4096 11月 26 08:54 2014 defaults
drwxr-xr-x 3 root root 4096 11月 26 08:54 2014 files
drwxr-xr-x 2 root root 4096 11月 26 08:54 2014 handlers
drwxr-xr-x 2 root root 4096 11月 26 08:55 2014 meta
drwxr-xr-x 2 root root 4096 11月 26 08:54 2014 tasks
drwxr-xr-x 3 root root 4096 11月 26 08:54 2014 templates
drwxr-xr-x 2 root root 4096 11月 26 08:54 2014 vars
![Page 22: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/22.jpg)
Ansible Galaxy!
あとはGalaxy上からAddする↓
![Page 23: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/23.jpg)
Ansible Galaxy!③README.mdの中身はこんな感じで、Galaxyに上げたあとのトップ画面に出るっぽい。[root@ansiblesvr001 ~]# head aerospike/README.md
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role
uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
![Page 24: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/24.jpg)
Ansible Galaxy!
④metaのmain.ymlの中身にcategoriesと書かれていて、デフォルトはコメントアウトされている。#を消して、今回Aerospikeなのでdatabase:nosqlをコメント解除した。その後Galaxyに上げるとdatabase:nosqlのカテゴリー内に無事アップされた
[root@ansiblesvr001 ~]# cat aerospike/meta/main.yml | more
# Below are all categories currently available. Just as with
# the platforms above, uncomment those that apply to your role.
#
categories:
#- cloud
#- cloud:ec2
#- cloud:gce
#- cloud:rax
#- clustering
#- database
- database:nosql
#- database:sql
#- development
#- monitoring
#- networking
#- packaging
#- system
![Page 25: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/25.jpg)
Ansible Galaxy!
![Page 26: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/26.jpg)
こうしてインフラチーム幸せになりました
「一番信頼できる作業が人力」を撲滅してゆくヾ( ̄∇ ̄=ノ
![Page 27: ansible 社内お勉強会資料](https://reader035.vdocuments.pub/reader035/viewer/2022081720/55965ef31a28abc2488b46ed/html5/thumbnails/27.jpg)
ご清聴ありがとうございました!