Blog | ytyng.comhttps://b.ytyng.com/blog/2024-03-19T05:23:18+00:00BlogUbuntu 16.04 に Docker CE をインストールする Ansible Playbook2018-02-27T01:27:56+00:002024-03-19T05:23:18+00:00ytynghttps://b.ytyng.com/blog/author/ytyng/https://b.ytyng.com/blog/ubuntu-1604-%E3%81%AB-docker-ce-%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%99%E3%82%8B-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>こんな感じかなあ…</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>