ansibleを使用してnginxやDockerを単純インストール
事前準備
事前にAnsibleをインストールしておく、ssh-keygen -t rsaでキーを作成してキーでログインできるようにする。
共通設定
接続などの共通設定をいかに示す
inventory.yml
web:
hosts:
hostname
vars:
domain: helloworld.com
ansible_user: username
ansible_ssh_private_key_file: ~/.ssh/id_rsa
ansible_sudo_pass: test_password
nginxをインストールする場合
aptコマンドを使用して単純にインストール
nginx.yml
- hosts: web
become: yes
tasks:
- name: "install nginx"
apt:
name: ['nginx']
state: latest
実行結果メモ
$ ansible-playbook -i inventory.yml nginx.yaml
PLAY [web] ********************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************
ok: [hostname]
TASK [install nginx] **********************************************************************************************************************************************
changed: [hostname]
PLAY RECAP ********************************************************************************************************************************************************
hostname : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
nginxサーバが動いていることの単純な動作確認
$ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
dockerの単純インストール
aptを使用して単純にインストールするだけの動作
docker.yaml
- hosts: web
become: yes
tasks:
- name: "install docker.io"
apt:
name: ['docker.io']
state: latest
実行結果
$ ansible-playbook -i inventory.yml docker.yaml
PLAY [web] ********************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************
ok: [hostname]
TASK [install docker.io] ******************************************************************************************************************************************
changed: [hostname]
PLAY RECAP ********************************************************************************************************************************************************
hostname : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
dockerが動いていることの確認
$ sudo docker ps
[sudo] username のパスワード:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Author And Source
この問題について(ansibleを使用してnginxやDockerを単純インストール), 我々は、より多くの情報をここで見つけました https://qiita.com/karosuwindam/items/5e5d1e78284f12ed1cf5著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .