LoginSignup
3
5

More than 3 years have passed since last update.

Ansible 超入門

Posted at

Ansible 超入門

概要

この記事はAnsibleとは何か?、どう使うのか?を端的にまとめた記事です。

前提と対象読者は以下です。

  • Ansibleってなんですかという状態かつ細かい説明はいいからとにかく使ってみたいという方向け

  • Ubuntu 16.04上で動かす

  • localhost上でAnsibleを動かしlocalhostの環境構築をすることを目的とする

  • とりあえずnginxを入れてみる

Ansibleとは

Ansibleとはなにか?

  • 構成管理ツール
    開発・運用に必要なパッケージなどをスクリプトに従い自動でインストールしてくれる

  • Ansibleの入っているサーバとPython導入済みでSSHサーバの稼働している対象サーバがあれば使用できる(エージェント不要)

  • Ansibleの入っている対象サーバのみでもよい

使い方

1.Ansibleをインストール

sudo apt install ansible

2.hostsで対象サーバを指定する

/etc/ansible/hostsを以下のように編集

# This is the default ansible 'hosts' file.
...中略...
#db-[99.101]-node.example.com

[ansible-test] # Playbookの実行対象グループ
localhost # 実行対象のサーバ

3.Playbookを作成する

ansible.ymlを作成する

- hosts: ansible-test
  connection: local
  tasks:
    - name: install nginx
      apt:
        name: nginx
        state: latest

4.playbookを実行する

sudo ansible-playbook -i /etc/ansible/hosts ansible.yml

こんな感じの出力が出ていればOK

PLAY RECAP ************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0
3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5