2017-05-14 16 views
1

ループ内で複数の変数を登録しますは、私は、変数のYAMLファイルを持っている

clientexists = true 
nodeexists = true 
gatewayexists = false 
icexists = true 
consulexists = false 

何らかの理由で、itemと:ファイルが存在するかどうかまたはfalse連結が機能していません。

どうすれば実現できますか?

答えて

2

これがあなたを助けてくれるこの希望を試してください。 Stats.ymlにループしている間に、msgフィールドには希望する出力が含まれます。

Variables.ymlHere we are defining variables

--- 
apps: 
    - client 
    - node 
    - gateway 
    - ic 
    - consul 

Stats.yml

--- 
- hosts: localhost 
    name: Gathering facts 
    vars_files: 
    - /path/to/variables.yml 
    tasks: 
    - name: "Here we are printing variables" 
    debug: 
    msg: "{{apps}}" 

    - name: "Here we are gathering stats and registering it" 
    stat: 
    path: "/etc/init.d/{{item}}" 
    register: folder_stats 
    with_items: 
    - "{{apps}}" 

    - name: "Looping over registered variables, Its msg field will contain desired output" 
    debug: 
    msg: "{{item.invocation.module_args.path}}: {{item.stat.exists}}" 
    with_items: 
    - "{{folder_stats.results}}" 

... 

folder_stats個別に1を参照するため、全体の結果が含まれています - 単一の結果はあなたがこのようにそれを使用することができますあなたのプレイブック。

folder_stats.results[0].stat.exists 
folder_stats.results[1].stat.exists 
folder_stats.results[2].stat.exists 
folder_stats.results[3].stat.exists 
+0

後で 'folder_stats'を変数として使うことはできますか?私はそれが存在する場合は、どのように私はそれを行うことができます各アプリを見る必要がありますか? – Moshe

+0

@Mosheこの演習では、次のように 'with_items: - " {{folder_stats.results}} "をループとして使用することができます –

+0

ループ中にループ 'ok :, ... '変更 ":偽、 "呼び出し":{ "module_args":{ "checksum_algorithm": "SHA1"、 "従う":偽、 "get_checksum":真、 "get_md5":真、 " パントマイム「偽、 "パス": "/etc/init.d/consul" }、 "モジュール名": "STAT" }、 "アイテム": "領事"、 "STAT":{"msg": "/etc/init.d/consul:False" } "msg": "/etc/init.d/consul:False" } ' –

関連する問題