カメニッキ

カメとインコと釣りの人です

ansibleメモ

どれもマニュアルに載ってるやつです

command

ansible

指定したホストに対し、単一モジュールの実行を行う

[~]$ ansible hostA -i inventory -m ping
hostA | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

ansible-console

指定したホストに対し、インタラクティブにモジュール実行を行う

[~]$ ansible-console hostA:hostB -i inventory
Welcome to the ansible console.
Type help or ? to list commands.

tahira@hostA*:hostB* (2)[f:5]$ ping
hostA | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
hostB | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

ansible-doc

モジュールのドキュメントを表示

# モジュールの一覧表示
[~]$ ansible-doc -l
a10_server                         Manage A10 Networks AX/SoftAX/Thunder/vThunder devices
a10_service_group                  Manage A10 Networks devices' service groups
a10_virtual_server                 Manage A10 Networks devices' virtual servers
acl                                Sets and retrieves file ACL information.
add_host                           add a host (and alternatively a group) to the ansible-playbook...
airbrake_deployment                Notify airbrake about app deployments
・・・
# yumモジュールのドキュメント表示
[~]$ ansible-doc yum
> YUM

  Installs, upgrade, removes, and lists packages and groups with the `yum' package manager.

Options (= is mandatory):

- conf_file
        The remote yum configuration file to use for the transaction.
・・・

ansible-galaxy

世界中のansibler(?)の作ったRoleを入手できる

[~]$ ansible-galaxy install username.jenkins

ansible-vault

ソースコード管理に平文のまま登録したくない情報を暗号化できる

# 暗号化
[~]$ ansible-vault encrypt private.yml
# 暗号化したプレイブックを実行する場合は--ask-vault-passを指定して実行する
[~]$ ansible-playbook -i inventory private.yml --ask-vault-pass
# 修正する場合は復号化する
[~]$ ansible-vault decrypt private.yml

option

※ 主にansibleコマンドに対するもの

やりたいこと option
sudoして実行 -s
パスワードが必要なsudo -sK
sudoユーザの指定 -U SUDO_USER
inventory & ホストで処理対象となるホスト確認 –list-hosts
並列数の指定 -f 10
使用するモジュール指定 -m shell
モジュールにわたす引数 -a ARGS (例: -m shell -a ‘uname -a’)
実行ユーザ指定 -u USERNAME
タイムアウト時間指定 -T 5
ログ出力 -t logfilename (例:
-t logs/date +%Y/date +%m/date +%d/date +%H%M
)