2016-10-20 20 views
0

Filebitプロペプタの1つをインストールする場合は、サービスの再実行がホスト上で実行されている必要があります。そのために、私は{{item.id}}を使ってデフォルトのプロスペクターリスト(redis、aerospike、postgress)を作成します。しかし、今は私が「いつ」に何らかの表現を書いておきたいのです。それは、実行中の場合にのみ、レディス用のプロスペクターをインストールします - どうすればいいのですか?どのモードをいつモードに設定しますか?

- name: Configure Filebeat prospectors 
    template: src=filebeat_conf.yml.j2 dest=/etc/filebeat/conf.d/{{ item.id }}.yml 
    notify: restart filebeat 
    with_items: prospectors 
    when: { " service: " } 
+0

なぜあなたは一時的な状態(Redisの実行中かどうか)に基づいて何かを設定するには、宣言型言語を使用しますか? – techraf

+0

私はこれを正しく行うために今dkしてください - あなたがそれを行う方法を提案できれば - してください。 – dezzinto

+0

それは問題ではありません**どのように正しく行うのですか?**何をするか** **なぜ**? – techraf

答えて

0

2つにタスクを分割する:事実を収集し、事実に応じて行動します。
インストールされているサービスを最初にリストし、既存のサービスのみを設定することができます。例えば

- hosts: test-host 
    vars: 
    services: 
     - name: apache2 
     id: 1 
     - name: nginx 
     id: 2 
     - name: openvpn 
     id: 3 
    tasks: 
    - name: get list of services 
     shell: "service --status-all 2>&1 | awk {'print $4'}" 
     args: 
     warn: false 
     register: services_list 

    - name: process only existing services 
     debug: msg="service {{ item.name }} with id={{ item.id }} exists" 
     with_items: "{{ services }}" 
     when: item.name in services_list.stdout_lines 
関連する問題