2016-10-21 28 views
0

私はAnecessを使用して各サーバーに固有の番号を挿入しようとします。以下のようにエラー:条件付きの評価中にエラーが発生しました

、私はこれらをされたい:

"1" 192.168.60.7のmyid.txtで192.168.60.6のmyid.txt

"2" に

- hosts: all 
    gather_facts:True 
    vars: 
    servers: 
     host1: 
     ip: 192.168.60.6 
     num: 1 
     host2: 
     ip: 192.168.60.7 
     num: 2 
     host3: 
     ip: 192.168.60.8 
     num: 3 

    tasks: 
    -name: write a unique number in myid.txt 
    lineinfile: 
     dest: "/home/user/myid.txt" 
     line: "{{ item.value.num }}" 
    when: "{{ item.value.ip }} == {{ ansible_all_ipv4_addresses[1] }}" 
    `enter code here`with_dict: "{{ servers }}" 

残念ながら、私はこのエラーを得た:

TASK [write unique number in myid] 

********************************************* 
fatal: [192.168.60.6]: FAILED! => {"failed": true, "msg": "The conditional check '{{item.value.ip}} == {{ ansible_all_ipv4_addresses[1] }}' failed. 
The error was: error while evaluating conditional ({{item.value.ip}} == {{ ansible_all_ipv4_addresses[1] }}): float object has no element 60 

The error appears to have been in '/home/shihhao/Desktop/BlueTech/ansible/kafka_playbook.yml': line 101, column 7, 
but may be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 
    - name: write unique number in myid 
    ^here\n"} 

私はこの行を追加すると、私はエラーになりますようです。

when: "{{item.value.ip}} == {{ ansible_all_ipv4_addresses[1] }}" 

はところで:{{ansible_all_ipv4_addressesは、[1]}}である192.168.60.6

答えて

0

あなたのwhen:声明の中で裸の変数を使用する必要があります。documentationから

when: item.value.ip == ansible_all_ipv4_addresses[1] 

This is easy to do in Ansible with the when clause, which contains a raw Jinja2 expression without double curly braces

生の表現はwhen:ステートメントで使用されています.wi assertモジュールであり、debug: var=varnameしかしdebug: msg="{{varname}}")です。

+0

ありがとうKonstantin。 – LImoritakeU

+0

ありがとうございましたが、今私は裸の変数を使用すべきかどうか混乱しており、もう1つは "{{}}"変数を使用する必要があります。 – LImoritakeU

関連する問題