ansible-playbook playbook.example.unique.yml ... TASK [debug] ***************************************************************************************************************************************** ok: [localhost] => { "msg": [ "user1", "user2" ] } TASK [debug] ***************************************************************************************************************************************** ok: [localhost] => { "msg": [ { "host": "local1", "user": "user1" }, { "host": "local2", "user": "user2" } ] }
registerの結果の型が不明な時等に便利
- debug: msg: "{{ result.stdout | type_debug }}"
- debug: msg: "{{ result.json | json_query('{key1: key1, key2: key2}') }}"
JP_VER=0.1.3 wget https://github.com/jmespath/jp/releases/download/$JP_VER/jp-linux-amd64 sudo mv jp-linux-amd64 /usr/local/bin/jp sudo chmod +x /usr/local/bin/jp
echo '[{ "key":"value1" },{ "key":"value2" }]' | jp '[]' [ { "key": "value1" }, { "key": "value2" } ] echo '[{ "key":"value1" },{ "key":"value2" }]' | jp '[].key' [ "value1", "value2" ] echo '[{ "key":"value1" },{ "key":"value2" }]' | jp "[?key=='value1']" [ { "key": "value1" } ]
loop: "{{ list1 | product(dict1) | list }}"
"{{ 60 | random(seed=inventory_hostname) }} 0 * * * root /script/from/cron"
# var1が必須ではないパラメータの場合、省略できる item.var1 | default(omit) # var1が未定義時に空の配列を返す item.var1 | default([])
when: (item.var1 | default("")) == "foo"