LoginSignup
65
63

More than 5 years have passed since last update.

ansibleでshellやcommandを使う時の注意点

Last updated at Posted at 2013-09-23
  1. shell
    shellはリモートノードのシェル(/bin/sh)を通して実行される。 次の文字を使用できる。
    $HOME, "<", ">", "|", "&"
  2. command
    commandは次の文字を使用できない。
    $HOME, "<", ">", "|", "&"
  3. 環境変数の読み込み
    ansibleではtask毎にシェルを起動して実行している(みたい。)
    つまり前のtaskで次のように環境変数を読み込み、次のtaskで利用する…ということができない。
export   KEY=VALUE
or
source ~/perl5/perlbrew/etc/bashrc (perlbrewの場合)

perlbrewのインストール手順で、source ~/perl5/perlbrew/etc/bashrcなどがあるが、上記のため、そのままでは使用できない。

そこで、bashの読み込み順に着目して、使用する。

~/.bashrc  シェル起動毎に読み込む  
~/.bash_profile  システム起動時に読み込む

つまり、次のtaskでも使用したい場合は、~/.bashrcに環境変数の読み込みなどを定義しておく。
ただし、本来はシステム起動時に読みこめばいいので、最後のTaskなどで削除して~/bash_profileで指定したほうがいいかも。

65
63
3

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
65
63