LoginSignup
100
100

More than 5 years have passed since last update.

[Ansible] コマンドチートシート

Last updated at Posted at 2014-07-01

Ansibleとは

ChefやPuppetになどに代表される構成管理ツールのひとつ。

Ansibleチートシート

yum でのインストール

- name: Install git
  yum: name=git state=latest

github からの clone

- name: clone ffmpeg
  git: repo=git://source.ffmpeg.org/ffmpeg.git dest=/tmp/ffmpeg
  sudo: yes
  poll: 30
  async: 600

poll と async は処理に時間が掛かる場合にタイムアウトしないように付ける。

filesディレクトリにあるファイルをコピー

- name: create sshd_config
  copy: src=sshd_config dest=/etc/ssh/sshd_config mode=600
  sudo: yes

templatesディレクトリにあるファイルをコピー

- name: Copy httpd.conf
  template: src=httpd.conf dest=/etc/httpd/conf/
  sudo: yes

ファイルをコピーしたときに、所有者・グループ・パーミションを指定する

owner、group、mode をつける

- name: create install.sh
  copy: src=install.sh dest=/home/myuser/scripts/ owner=myuser group=mygroup mode=755
  sudo: yes

ファイルをダウンロード

- name: download php
  get_url: url=http://jp1.php.net/get/php-5.3.28.tar.gz/from/this/mirror dest=/tmp

エラーを無視

下記を追加する

  ignore_errors: yes

特定のディレクトリにcdしてコマンド実行

chdir=*** をつける

- name: make qmail
  command: make chdir=/tmp/qmail-1.03
  sudo: yes

ループ処理

- name: create dirs
  command: mkdir -p /tmp/{{item}}
  sudo: yes
  with_items:
      - dir_a
      - dir_b
      - dir_c
      - dir_d

その他

ここも参考になる
http://inforno.net/articles/2013/10/15/ansible-tips

100
100
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
100
100