Ansible Documentation
shell – Execute commands in nodes.機能
- 対象ホストのシェル経由でシェルコマンドを実行する
- 環境変数やパイプ、リダイレクトなども使用できる
パラメータ
| パラメータ | 選択肢/ Default | 説明 |
|---|---|---|
| chdir | - | シェルコマンドの実行前に指定したディレクトリに移動する |
| creates | - | 指定したファイルが存在しているとき、シェルコマンドを実行しない = 指定したファイルが存在していないとき、シェルコマンドを実行する |
| executable | - | シェルコマンドを実行するシェルを変更する |
| removes | - | 指定したファイルが存在していないとき、シェルコマンドを実行しない = 指定したファイルが存在しているとき、シェルコマンドを実行する |
例
- name: カレントディレクトリのファイルの一覧を ls.txt に保存する shell: ls -al > ls.txt
- name: ~/ls.txt ファイルが存在しないとき、 /etc ディレクトリのファイルの一覧を ~/ls.txt に出力する
shell: ls -al > ~/ls.txt
args:
creates: ~/ls.txt
chdir: /etc
- name: /tmp ディレクトリに移動し、ファイルの一覧を ~/ls.txt に追記する
shell: ls >> ~/ls.txt
args:
chdir: /tmp
- name: csh で date コマンドを実行する
shell: date
args:
executable: /bin/csh
- name: ls.txt ファイルが存在するとき、その内容を表示する
shell: cat < ls.txt
args:
removes: ls.txt