Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Ansible把握した 1日目
Search
Masaru OKI
February 20, 2021
Technology
430
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ansible把握した 1日目
構成管理ツールAnsibleをざっと触ってみて、現時点での理解をまとめてみました。
Masaru OKI
February 20, 2021
More Decks by Masaru OKI
See All by Masaru OKI
SONiCを自前でビルドする話
imasaruoki
2
1.9k
NPLによるデータプレーンプログラミング
imasaruoki
8
2.9k
SONiC近況報告 2019/Fall
imasaruoki
1
1.4k
ホワイトボックススイッチをAnsibleで操る話
imasaruoki
2
2.7k
ホワイトボックススイッチとNOSを取り巻く状況について
imasaruoki
3
2.7k
SONICイントロダクション
imasaruoki
1
600
SONiCをはじめてみよう
imasaruoki
6
2.5k
SONiCで設定するFRRouting
imasaruoki
0
2k
SONiCトラブルシューティング
imasaruoki
4
750
Other Decks in Technology
See All in Technology
『GOエコノミー 』(相乗りサービス) におけるスペック駆動開発
mot_techtalk
1
310
AgentCoreで実践するハーネスエンジニアリング
yakumo
1
280
OpenSharing について熱く語る〜AI アセットの共有について〜
kameitomohiro
0
230
IoTデバイスを繋げるプロトコルMatterをAndroidで使用する方法
harutiro
0
120
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
120
[2026 Oracle Technical Deep Dive] AI時代のデータベース基盤をどう選ぶ? Exadata Database Serviceの選択肢と使い分け (2026年9月17日開催)
oracle4engineer
PRO
0
220
Datadog の学び方 - あるいは、オブザーバビリティを学ぶとは何か
mananyuki
1
440
AI Made Us Faster at Solving the Wrong Problems
marceloancelmo
0
160
Kernel testing frameworks
ennael
PRO
0
110
[2026 Oracle Technical Deep Dive] エンタープライズAIエージェントを支えるOCIソリューション。ラインナップと特徴を理解しよう! (2026年9月17日開催)
oracle4engineer
PRO
0
510
全人類(ほぼ)AWS Organizations の上でAWSを利用している、その世界を知る話
htan
0
110
SDDの運用にめげずに向き合った話
sansantech
PRO
0
130
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
270
The Mindset for Success: Future Career Progression
greggifford
PRO
0
530
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
510
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
610
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
What's in a price? How to price your products and services
michaelherold
247
13k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
260
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
610
Transcript
Ansible把握した 1日目 Feb 20, 2021 Masaru OKI @masaru0714
Ansible? 構成管理ツール。ChefとかPuppetとかも構成管理ツール。 サーバやネットワーク機器にいろいろな設定を入れるためのツール。 対象によるがソフトウェアのインストールなどもできる。 sshで入れてPythonが動く機器ならどうにかできる。 インストールは公式サイトの指示に従って。
ansibleとansible-playbook ワンライナー的な一発実行はansibleコマンド(全ホストにpingを打つとか) ansible all -m ping 複数のタスクをまとめて実行する場合はansible-playbookコマンド ansible-playbook deploy.yml ホストの一覧(とsshすべきIPアドレス)はinventoryと呼ばれるファイルに書く。
(ファイル名がinventoryというわけではない)
実行準備 ターゲットホストにsshでログインできるようにしておく必要がある。 ターゲットホストに~/.ssh/authorized_keysを置くのが一般的のようだ。 rootである必要はないが、その場合sudoできること(doasなども選べる)。
ansible-playbook おおざっぱな概略図 h1 h2 h3 h4 [db] h1 ansible_ssh_host=192.168.0.1 h2
ansible_ssh_host=192.168.0.2 [web] h3 ansible_ssh_host=192.168.0.3 h4 ansible_ssh_host=192.168.0.4 hosts (inventory) ホストとグループの定義 変数も定義できる - hosts: db roles: - dev-sec.mysql - hosts: web roles: - nginxinc.nginx Playbook ホストやグループごとに何 を構成するかの定義 taskを直接書くか、あるい はroleを指定する nodes: h1: mysql_databases: - name: customer h2: mysql_databases: - name: statistics h3: nginx_start: false h4: nginx_debug_output: true role dev-sec.mysql role nginxinc.nginx customer statistics nginx install nginx install nginx start debug output 外部変数ファイル (これもinventory) 構成の設定値や挙動の指定 この例ではnodesグループのホ ストh1,h2,h3,h4の変数を定義 している role=定義済task task (mysql_db呼出) task (apt呼出)
用語解説 moduleは構成対象のホストで実行されるプログラム。 inventoryはパラメータの集合。ホストの識別名とIPアドレスが必要。 taskはinventoryから必要な情報を引き出してmoduleを使って実行。 roleは繰り返し使われるtaskのパラメータを変数にして呼出可能にしたもの。 Playbookはホストあるいはグループとtaskやroleとの組み合わせを記述する。
taskとmodule Playbook tasks: - name: やることを人間にわかるように書く ここがmodule名: moduleに与えるパラメータ: 値 をわらわら並べる
- name: Webサーバを起動する service: name: httpd state: started
taskとinventory inventory h1: webserver: started Playbook - hosts: h1 tasks:
- name: Webサーバを用意する(起動はinventory次第) service: name: httpd state: {{ webserver }}
roleとtask Playbookに記載するtaskを別ファイルに切り出して名前をつけたのがrole Playbook roles: - role名 で呼び出す。 • 呼び出したroleがどんな変数を参照しているかはドキュメントかソースを読む。 •
自作roleを用意することもできる。 roles/role名/task/main.ymlに - name: から記述する。 • 既存のroleがたくさんあり、ansible-galaxyコマンドでインストールできる。 • ansible-galaxy search キーワードで検索できる。 • ありすぎてどれを使えばいいのかわからない。 公式があればなるべくそれを。
Playbookとtask,role Playbook - hosts: 識別子(ホストでもグループでもいい) tasks: - name: 識別子のホストで実行するタスクを並べる service:
name: httpd roles: - gobgp - hosts: 識別子 以下略
inventory(変数)はどこに書く? 書ける箇所がたくさんありすぎる。 • グローバルなのは/etc/ansible/hosts • ansible-playbookコマンドのパラメータで直接指定 • ansible-playbookコマンドの-iでファイルを指定できる • Playbookの中でvars:指定で書くこともできる
• host_vars/ホスト識別子.yml に書くこともできる • group_vars/グループ識別子.yml に書くこともできる • group_vars/all.yml に全部まとめて書くこともできる どこに書かれた値を使うかの優先順位がある。 複数箇所に書くと混乱するので注意。
inventory(hosts)のフォーマット hosts (INI形式) [Guests] guest1 ansible_ssh_host=192.168.122.116 guest2 ansible_ssh_host=192.168.122.117 hosts.yml (YAML
形式) all: children: Guests: hosts: guest1: ansible_ssh_host: 192.168.122.116 guest2: ansible_ssh_host: 192.168.122.117
hosts(あるいはhosts.yml)の場所 ansible.cfg(実はこれの場所もあちこちに用意できる)に [defaults] inventory = 任意のpath と書いておくと、/etc/ansible/hostsではなくそこが参照される。 あるいは、明示的に ansible-playbook -i
任意のpath と指定する。
やってみた(VMの2本めの足にIPアドレスを振る) • VMが起動していることが前提。 • IPアドレスは192.168.122.116/24でホストからアクセスできる。 • 試したVMはUbuntu 20.04LTS • アカウントはubuntu
• ~/.ssh/authorized_keys配置済 • パスワードレスでsudoできることも確認済。 • ネットワークインタフェースはens3, ens4。ens3はAnsibleとの通信用。
やってみた(VMの2本めの足にIPアドレスを振る) deploy.yml - hosts: Guests user: ubuntu become: yes become_method:
sudo roles: - mrlesmithjr.config-interfaces hosts [Guests] guest ansible_ssh_host=192.168.122.116 group_vars/all nodes: guest: network_interfaces: - name: ens4 method: static address: 192.168.0.1 netmask: 255.255.255.0 ansible.cfg [defaults] inventory=hosts 実行 ansible-galaxy install mrlesmithjr.config-interfaces ansible-playbook -i hosts deploy.yml
まとめ • Ansible便利! • 下準備がちょっと面倒だけど! • role山盛りあってどれがちゃんと使えるか探すの大変だけど!