2017-11-07 9 views
0

threadのように、変数をAnabilitiesのリストに追加しています。私は私のserverListペイロードがNO ifループが存在しない場合、それは完璧に動作リストへの追加/不可能な変数の変数へのキーの追加

"Unexpected templating type error occurred on 
({% if item.hostGroup == 'webgroup' %} {{my_group + [item.hostname]}} 
{% endif %}): coercing to Unicode: need string or buffer, list found"} 

以下のようなエラーを取得

{ 
    "hostGroup": "dbgroup", 
    "hostname": "db_server_usa_01" 
}, 
{ 
    "hostGroup": "webgroup", 
    "hostname": "web_server_usa_01" 
} 

のように見えます

- name: "Initialize variables" 
    set_fact: 
     my_group: [] 

- set_fact: 
     my_group: 
     "{% if item.hostGroup == "webgroup" %} 
      {{my_group + [item.hostname]}} 
     {% endif %}" 
    with_items: "{{serverList}}" 

ロジックmy_group: {{my_group + [item.hostname]}}

を使用しています。どのようにこの作品を作るための任意のアイデアループ if

答えて

1

これは良く見えませんか?

- name: "Initialize variables" 
    set_fact: 
     my_group: "{{ serverList | selectattr('hostGroup','equalto','webgroup') | map(attribute='hostname') | list }}" 
+0

wow。それははるかに良いです。どうもありがとう – diaryfolio

関連する問題