2017-09-26 10 views
0

私は以下のようなプレイブックを持っています。式の値を変数として定義できますか?

- name: ensure crm service is exist 
    shell: crm resource status {{item.service}} 
    register: is_service_exist 
    with_items: "{{crm_services}}" 
    run_once: true 
    delegate_to: "{{controller_master}}" 
    when: crm_services is defined 
    ignore_errors: True 

    - name: msg 
    vars: 
     service_is_exist: var[{{is_service_exist.results[0].stderr.find('not found')}}==-1] 
    debug: msg={{service_is_exist}}] 

    - name: stop crm service 
    shell: crm resource stop {{item.service}} 
    with_items: "{{crm_services}}" 
    run_once: true 
    delegate_to: "{{controller_master}}" 
    when: crm_services is defined and is_service_exist.results[0].stderr.find('not found')==-1 

    - name: uninstall current rpm packages 
    shell: rpm -e --nodeps {{item.package}} 
    with_items: "{{packages}}" 
    ignore_errors: True 

crm_serviceが存在するかどうか、crm_serviceが存在するかどうかを知りたい場合は、サービスを停止し、現在のrpmパッケージをアンインストールします。 私はis_service_exist.results[0].stderr.find('not found')==-1が読みやすいとは思いませんので、私は変数として式を設定したいと思いますか?

私はvar[{{is_service_exist.results[0].stderr.find('not found')}}==-1]を試してみましたが、出力は、この "MSG" のようなものです: "のvar [-1 == - 1]" だから

、変数と式の値を定義ansibleことができますか?

答えて

0

私は通常、それぞれregisterの後にset_factを使用して、迷惑データを取り除きます。

- name: ensure crm service is exist 
    shell: crm resource status {{item.service}} 
    register: is_service_exist 
    with_items: "{{crm_services}}" 
    run_once: true 
    delegate_to: "{{controller_master}}" 
    when: crm_services is defined 
    ignore_errors: True 

- set_fact: 
    is_service_exists: "{{is_service_exist.results[0].stderr.find('not found') == -1}}" 

- name: stop crm service 
    shell: crm resource stop {{item.service}} 
    with_items: "{{crm_services}}" 
    run_once: true 
    delegate_to: "{{controller_master}}" 
    when: crm_services is defined and is_service_exist 
関連する問題