LoginSignup
3
9

More than 5 years have passed since last update.

初めてのAnsible(1章:イントロダクション)

Last updated at Posted at 2016-11-12

「初めてのAnsible」 を読み進めながらのメモ

環境

  • macOS Sierra version10.12.1
  • Ansible 2.2.0.0
  • Vagrant 1.8.7
  • VirtualBox 5.1.8

Ansible インストール

Homebrew が入っていれば下記コマンドで

$ brew update
$ brew install ansible

テストサーバーとして Vagrant を準備

Vagrant については下記などを参考に

Vagrant 1.8.7 では vagrant up 時にエラーが発生したため下記で対応

下記コマンドで Ubuntu 14.04.5 の 64bit 仮想マシンイメージのための Vagrantfile を作成し起動

$ vagrant init ubuntu/trusty64
$ vagrant up

テストサーバーを Ansible に明示

仮想マシンを立ち上げたディレクトリに hostsansible.cfg を作成

hosts
testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222

サーバーに testserver というエイリアスを付与し、Vagrant 利用時の host と port を設定

ansible.cfg
[default]
hostfile = hosts
remote_user = vagrant
private_key_file = .vagrant/machines/default/virtualbox/private_key
host_key_checking = False

hostfile : インベントリファイルの場所
remote_user : SSHのユーザー
private_key_file : SSHの秘密鍵
host_key_file : Vagrant 利用時、マシンの生成毎に ~/.ssh/known_hosts ファイルをいじらなくて済むようにするため設定

ansible コマンド

Ansible を利用しサーバーに接続できることを確認するなど、アドホックな処理に利用

オプション

  • -m : モジュールを指定
  • -s : sudo で実行
  • -a : クォートで囲んでコマンドを直接指定

など。
Introduction To Ad-Hoc Commands に書いてある

3
9
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
9