chef knifeコマンド めも
knifeコマンドのめも
- sshオプション
自動的にsshでログインしてコマンドを叩けるオプション。管理サーバからリモートホストへまとめてコマンドを叩けるので便利。
webサーバにchef-clientを実行。
knife ssh "hostname:web*" -x user "sudo chef-client" -i /home/user/.ssh/id_rsa
hostnameにマッチするディスク容量調べてみたり。
knife ssh "hostname:web*" -x srvadm "df -h" -i /home/user/.ssh/id_rsa # knife ssh "os_version:*" -x user "df -h" -i /home/user/.ssh/id_rsa web01 Filesystem Size Used Avail Use% Mounted on web0 /dev/mapper/VolGroup00-LogVol00 web01 39G 22G 16G 60% / web01 /dev/sda1 244M 27M 204M 12% /boot web01 tmpfs 3.9G 0 3.9G 0% /dev/shm web02 Filesystem Size Used Avail Use% Mounted on web02 /dev/mapper/VolGroup00-LogVol00 web02 39G 10G 27G 28% / web02 /dev/sda1 244M 27M 204M 12% /boot web02 tmpfs 3.9G 0 3.9G 0% /dev/shm
QUERYはattributeからマッチしているようなのでこんな感じでも使える。
knife ssh "platform:centos" -x user "sudo yum update -y" -i /home/user/.ssh/id_rsa
platformがcentosだけyum update。
- オプションの一覧
# knife ssh -h knife ssh QUERY COMMAND (options) -a, --attribute ATTR The attribute to use for opening the connection - default is fqdn -s, --server-url URL Chef Server URL -k, --key KEY API Client Key --[no-]color Use colored output, defaults to enabled -C, --concurrency NUM The number of concurrent connections -c, --config CONFIG The configuration file to use --defaults Accept default values for all questions -d, --disable-editing Do not open EDITOR, just accept the data as is -e, --editor EDITOR Set the editor to use for interactive commands -E, --environment ENVIRONMENT Set the Chef environment -F, --format FORMAT Which format to use for output --[no-]host-key-verify Verify host key, enabled by default. -i IDENTITY_FILE The SSH identity file used for authentication --identity-file -m, --manual-list QUERY is a space separated list of servers -u, --user USER API Client Username --print-after Show the data after a destructive operation -G, --ssh-gateway GATEWAY The ssh gateway -P, --ssh-password PASSWORD The ssh password -p, --ssh-port PORT The ssh port -x, --ssh-user USERNAME The ssh username -V, --verbose More verbose output. Use twice for max verbosity -v, --version Show chef version -y, --yes Say yes to all prompts for confirmation -h, --help Show this message
公式のマニュアルはこちら
http://wiki.opscode.com/display/chef/Knife+Built+In+Subcommands