14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ansible モジュール command

Last updated at Posted at 2016-02-04

command

リモートノードでコマンドを実行する

概要

コマンド名+スペース区切りの引数の形で受け付ける。コマンドは選択された全てのノードで実行される。シェルを通して実行しない為、${HOME}のような記述や、<>|&のような記号は使用できない。(もしこれらの記述が必要であれば、shellモジュールを使うこと)

オプション

引数 必須 デフォルト 備考
chdir no 実行前に指定されたディレクトリに移動。
creates no ファイル名又はglobパターン(2.0以降)を作成。既に存在する場合、スキップされる。
executable no コマンドを実行するシェルを変更。シェルへの絶対パスであること。
free_form yes フリー形式のコマンドを実行可能。「free form」という引数は実際には存在しない。使用例を参照。
removes no ファイル名又はglobパターン(2.0以降)を削除。それらが存在しない場合、スキップされる。
warn
(1.8で追加)
no True ansible.cfgでcommand_warningsがオンになっている場合、no又はfalseに設定することにより、そのコマンドに関しては警告を出さない。

使用例

# Ansible Playbooksからの例
- command: /sbin/shutdown -t now

# 指定したファイルがない場合コマンドを実行する
- command: /usr/bin/make_database.sh arg1 arg2 creates=/path/to/database

# 「args」を使いオプションを設定可能。
# 作業ディレクトリをsomedir/に変更し、/path/to/databaseandが存在しない場合のみ実行される。
- command: /usr/bin/make_database.sh arg1 arg2
  args:
    chdir: somedir/
    creates: /path/to/database

注意点

  • シェルを通じてコマンドを実行したい(<、>、 |等を使う )場合、shellモジュールを使うことが推奨される。commandモジュールはユーザの環境によって影響を受けない為、より安全である。
  • 「creates」、「removes」、「chdir」はコマンドの後で指定する。例えば、あるファイルが存在しない場合のみコマンドを実行したい場合、これらを使用する。

Ansibleコアモジュール

このモジュールはコア・アンシブルチームによりメンテナンスされます。

14
10
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
14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?