tpaexec eval#
evalコマンドを使用して、クラスターのインベントリのコンテキストで任意のJinja/Ansible式を評価できます。情報は、変数、インベントリ、収集されたOSファクト、計算されたパス、パッケージ名などに関連する場合があります。
使用法#
tpaexec eval ~/clusters/speedy '<expression>'を実行します
オプション#
tpaexec eval ~/clusters/speedy '<expression>' --hosts <pattern>
評価をホストパターンに制限します。パターンは、単一のインスタンス名unreal
、コロン区切りリストunreal:ultra 、localhost
、またはグループ名role_primary 、role_etcd です。
tpaexec eval ~/clusters/speedy '<expression>' --no-init
クラスター初期化プレイブックをスキップします。 config.yml
および生成されたインベントリから派生した変数のみが使用できます。
ansible_*
ホストファクトは未定義になります。スピーディーな在庫確認におすすめです。
出力例#
単一ホストのconfig.yml から値を検索します。
tpaexec eval ~/clusters/speedy {{ postgres_version }} --no-init --hosts unreal
unreal => {
"msg": "17"
}
クラスター内のすべてのホストの値を出力します。
tpaexec eval ~/clusters/speedy {{ ip_address }} --no-init
unreal => {
"msg": "10.33.155.2"
}
ultra => {
"msg": "10.33.155.3"
}
quondam => {
"msg": "10.33.155.4"
}
localhost をターゲティングしてインベントリ全体のデータを検査します。
tpaexec eval ~/clusters/speedy {{ groups.keys() | list }} --no-init --hosts localhost
localhost => {
"msg": [
"all",
"ungrouped",
"tag_Cluster_speedy"
]
}
ホスト用に定義されたすべての変数をリストします必要な変数の名前がまだわからない場合に役立ちます。
tpaexec eval ~/clusters/speedy {{ hostvars[inventory_hostname].keys() | list | sort }} --no-init --hosts unreal
unreal => {
"msg": [
"ansible_user",
"backup",
"cluster_name",
"failover_manager",
"ip_address",
"postgres_version",
"role",
"..."
]
}
ホスト自分自身から収集されたファクトを読み取ります --no-init
を省略すると、初期化プレイブックが実行され、ansible_*
ファクトが設定されます。
tpaexec eval ~/clusters/speedy {{ ansible_distribution }} --hosts unreal
unreal => {
"msg": "Debian"
}