2017-05-03 4 views
0

with_items条件:Ansible:私は正常に動作脚本、そのような部分を持っている

しかし、私はそれは立派に見えるし、そのような何かをしたいと思います:

- name: "Copy solrconfig.xml" 
    copy: 
    src: "{{role_path}}/files/{{item.path}}" 
    dest: "{{solr_jmx_config}}/solrconfig.xml" 
    with_items: 
    - path: solrconfig_master.xml -> when: inventory_hostname == "{{ solr_master }}" 
    - path: solrconfig_slave.xml -> when: inventory_hostname != "{{ solr_master }}" 
    become: yes 
    become_user: solr 

特定の商品ごとに「いつ」の条件を適用するのですか?

敬具、あなたがここにwith_itemsrole_pathが必要なのはなぜ マレク

答えて

0

?これを試してみてください:

- name: "Copy solrconfig.xml" 
    copy: 
    src: "{{ 'solrconfig_master.xml' if inventory_hostname == solr_master else 'solrconfig_slave.xml' }}" 
    dest: "{{solr_jmx_config}}/solrconfig.xml" 
    become: yes 
    become_user: solr 

with_は、一般的に、ループのために使用されている、あなたは、単一の要素のためにそれを必要としません。
ロール内でタスクを呼び出すと、ファイルモジュールの検索パスには<role_path>/files/...が含まれます。

+0

こんにちはコンスタンチン、そのアプローチは実際に私のために働いた。答えをありがとう! –

関連する問題