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
440
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
2k
NPLによるデータプレーンプログラミング
imasaruoki
8
2.9k
SONiC近況報告 2019/Fall
imasaruoki
1
1.4k
ホワイトボックススイッチをAnsibleで操る話
imasaruoki
2
2.8k
ホワイトボックススイッチとNOSを取り巻く状況について
imasaruoki
3
2.7k
SONICイントロダクション
imasaruoki
1
600
SONiCをはじめてみよう
imasaruoki
6
2.5k
SONiCで設定するFRRouting
imasaruoki
0
2.1k
SONiCトラブルシューティング
imasaruoki
4
760
Other Decks in Technology
See All in Technology
渡米前の準備を制す!re:Invent 2026徹底準備術 / The Ultimate Preparation Guide for re:Invent 2026
yuj1osm
1
530
増え続けるプロダクトの品質をどう担保するか。ProductSpecとTypeScriptによる取り組み
joere
3
360
SLOを阻む不安
sraku2159
0
220
AIコーディングはじめました
miso
0
140
"AWSはちょっと苦手"でも大丈夫。AWS Blocks で手軽に作る Flutter のバックエンド #FlutterKaigi
tacck
PRO
0
130
2拠点SRE活動始めてみた | sogaoh's LT @ ホンマでっかSRE勉強会 #3
sogaoh
PRO
0
240
200人の配信コメント、 全部Jevが仕分けます 〜 マサカリガードを作ってみた 〜
katayamatg
1
530
生き様としてのSRE
hokkai7go
1
160
AIがGISを代替する日:〜すべてをAIが創る時代に、私たちがFOSS4Gに関わる意味〜
lehupa
0
200
Patterns in AI Driven Software Development
akosma
PRO
0
470
基本から分かる!AWSセキュリティ運用の考え方と任せ方
cmusudakeisuke
1
390
AX時代の自治体支援リソース再配分と役割分担の再構成:戦略とロードマップ(概要)
sishi2026
0
190
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
320
Ethics towards AI in product and experience design
skipperchong
2
460
エンジニアに許された特別な時間の終わり
watany
109
250k
Evolving SEO for Evolving Search Engines
ryanjones
0
350
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Mobile First: as difficult as doing things right
swwweet
225
10k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
650
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
120k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
390
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Designing Powerful Visuals for Engaging Learning
tmiket
1
630
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
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山盛りあってどれがちゃんと使えるか探すの大変だけど!