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.8k
SONiC近況報告 2019/Fall
imasaruoki
1
1.4k
ホワイトボックススイッチをAnsibleで操る話
imasaruoki
2
2.7k
ホワイトボックススイッチとNOSを取り巻く状況について
imasaruoki
3
2.7k
SONICイントロダクション
imasaruoki
1
590
SONiCをはじめてみよう
imasaruoki
6
2.4k
SONiCで設定するFRRouting
imasaruoki
0
2k
SONiCトラブルシューティング
imasaruoki
4
750
Other Decks in Technology
See All in Technology
白金鉱業Meetup Vol.25 アウトカムが二値のデータに対するCausal Impact
brainpadpr
0
290
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.6k
あけおめLINE 傾向とその対策
nasa9084
0
300
AIは推し活である。
kurazuuuuuu
1
950
ソフトウェアDNAとクラウドエージェントのススメ
cloudace
0
120
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
2.4k
Oracle Cloud Network Path Analyzerを試してみた/I Tried Out Oracle Cloud Network Path Analyzer
masakiokuda
1
110
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
5
1.9k
SREは、MCPとAutopilotをこう使え!
kazumax55
3
950
Claude in Chrome 入門 / Introduction to Claude in Chrome
cielo1985
0
890
Railsのように考える: See through the Master
snoozer05
PRO
5
1.3k
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
30
19k
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
41k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
250
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
The agentic SEO stack - context over prompts
schlessera
0
940
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
900
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
440
WENDY [Excerpt]
tessaabrams
14
39k
How to Ace a Technical Interview
jacobian
281
24k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
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山盛りあってどれがちゃんと使えるか探すの大変だけど!