---
slug: "ubuntu-1604-に-docker-ce-をインストールする-ansible-playbook"
title: "Ubuntu 16.04 に Docker CE をインストールする Ansible Playbook"
description: "Ubuntu 16.04 に Docker CE をインストールする Ansible Playbook の完全 YAML 例。apt 鍵追加、リポジトリ登録、docker-ce パッケージ導入までを自動化。"
url: "https://www.ytyng.com/blog/ubuntu-1604-に-docker-ce-をインストールする-ansible-playbook"
publish_date: "2018-02-27T01:27:56Z"
created: "2018-02-27T01:27:56Z"
updated: "2026-05-11T13:03:27.805Z"
categories: ["Ansible"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/af931d830e564784a96e5acb3f431666.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "ja"
---

# Ubuntu 16.04 に Docker CE をインストールする Ansible Playbook

<pre style="background-color: #ffffff; color: #000000; font-family: 'Menlo'; font-size: 9.0pt;">---<br />- <span style="color: #000080; font-weight: bold;">hosts: </span>servers<br />  <span style="color: #000080; font-weight: bold;">gather_facts: </span>no<br />  <span style="color: #000080; font-weight: bold;">become: </span>yes<br />  <span style="color: #000080; font-weight: bold;">tasks:<br /></span><span style="color: #000080; font-weight: bold;"><br /></span><span style="color: #000080; font-weight: bold;">    </span>- <span style="color: #000080; font-weight: bold;">apt:<br /></span><span style="color: #000080; font-weight: bold;">        name: </span>apt-transport-https<br /><br />    - <span style="color: #000080; font-weight: bold;">apt:<br /></span><span style="color: #000080; font-weight: bold;">        name: </span>ca-certificates<br /><br />    - <span style="color: #000080; font-weight: bold;">apt:<br /></span><span style="color: #000080; font-weight: bold;">        name: </span>curl<br /><br />    - <span style="color: #000080; font-weight: bold;">apt:<br /></span><span style="color: #000080; font-weight: bold;">        name: </span>software-properties-common<br /><br />    - <span style="color: #000080; font-weight: bold;">shell: </span><span style="color: #008000; font-weight: bold;">"apt list --installed |grep docker-ce"<br /></span><span style="color: #008000; font-weight: bold;">      </span><span style="color: #000080; font-weight: bold;">register: </span>docker_ce_installed<br />      <span style="color: #000080; font-weight: bold;">ignore_errors: </span>True<br /><br />    - <span style="color: #000080; font-weight: bold;">when: </span>docker_ce_installed|failed<br />      <span style="color: #000080; font-weight: bold;">block:<br /></span><span style="color: #000080; font-weight: bold;">        </span>- <span style="color: #000080; font-weight: bold;">shell: </span>apt-key list Docker<br />          <span style="color: #000080; font-weight: bold;">register: </span>apt_key_exists<br /><br />        - <span style="color: #000080; font-weight: bold;">when: </span>not apt_key_exists.stdout<br />          <span style="color: #000080; font-weight: bold;">shell: </span>curl -fsSL https://download.docker.com/linux/ubuntu/gpg |apt-key add -<br /><br />        - <span style="color: #000080; font-weight: bold;">shell: </span>grep download.docker.com /etc/apt/sources.list<br />          <span style="color: #000080; font-weight: bold;">register: </span>apt_source_docker_exists<br />          <span style="color: #000080; font-weight: bold;">ignore_errors: </span>True<br /><br />        - <span style="color: #000080; font-weight: bold;">when: </span>apt_source_docker_exists|failed<br />          <span style="color: #000080; font-weight: bold;">shell: </span>add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"<br /><br />        - <span style="color: #000080; font-weight: bold;">apt:<br /></span><span style="color: #000080; font-weight: bold;">            update_cache: </span>yes<br /><br />        - <span style="color: #000080; font-weight: bold;">apt:<br /></span><span style="color: #000080; font-weight: bold;">            name: </span>docker-ce</pre>
<p></p>
<p>こんな感じかなあ&hellip;</p>
<p></p>
<p>参考にしました:</p>
<p><a href="https://qiita.com/lynlea/items/e00248dd697059969203#4-%E8%A9%A6%E3%81%99" target="_blank">UbuntuにDocker CEをインストールする - Qiita</a></p>
<p></p>
