Skip to Content
Pythonによるテスト駆動開発, 3rd Edition
book

Pythonによるテスト駆動開発, 3rd Edition

by Harry Percival
October 2025
Intermediate to advanced
712 pages
9h 46m
Japanese
O'Reilly Media, Inc.
Content preview from Pythonによるテスト駆動開発, 3rd Edition

第12章 コードとしてのインフラ :Ansibleによる自動デプロイ

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

自動化せよ、自動化せよ、自動化せよ。

Cay S. Horstmann

サーバが起動して動作している状態になったので、 Dockerイメージとコンテナを使ってアプリをインストールする。

手動で行うことも可能だが、 現代のソフトウェアエンジニアリングにおける重要な知見は、 小規模で頻繁なデプロイが必須だということだ。

注記

頻繁なデプロイの重要性に関するこの知見は、 ニコール・フォースグレンと DevOpsレポートに負っている。 これらはソフトウェア工学分野において、数少ない確固たる科学的知見だ。

頻繁なデプロイは自動化に依存する。1 そこでAnsibleを使う。

自動化は、デプロイに対するテストの信頼性を確保する上でも重要だ。ステージングサーバを構築する手間をかけるなら、2 本番環境と可能な限り類似性を確保したい。 デプロイ方法を自動化し、ステージングと本番で同じ自動化を活用することで、 我々はより大きな信頼性を得られる。

近年のデプロイ自動化の流行語は「コードとしてのインフラ」(IaC)だ。

サイトが公開されたら、 私にメールで知らせてくれないか? URLを送ってくれ。 いつも温かい気持ちになるんだ…​メールはobeythetestinggoat@gmail.com まで。

Ansibleプレイブックによるデプロイの初歩

Ansibleをもう少し本格的に使ってみよう。ただし最初から最後まで一気に進めるわけじゃない。 いつも通り、小さな一歩から始めるんだ。 サーバ上でシンプルな「hello world」Dockerコンテナを実行できるか試してみよう。

古い「ping」関連のコンテンツを削除し、 次のような内容に置き換える:

infra/deploy-playbook.yaml (ch12l001)

---
- hosts: all

  tasks:

    - name: Install docker  1
      ansible.builtin.apt:  2
        name: docker.io  3
        state: latest
        update_cache: true
      become: true

    - name: Run test container
      community.docker.docker_container:
        name: testcontainer
        state: started
        image: busybox
        command: echo hello world
      become: true

Ansibleプレイブックは一連の「タスク」で構成される。現在複数存在する。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

イーサリアムをマスターする, 2nd Edition

イーサリアムをマスターする, 2nd Edition

Carlo Parisi, Alessandro Mazza, Niccolo Pozzolini, Gavin Wood, Andreas M. Antonopoulos
Excel用Python

Excel用Python

Felix Zumstein

Publisher Resources

ISBN: 0642572274771