2015-11-10 150 views
0

如何使用ansible(v1.9)playbook中的任何文件名爲postgres集羣創建配置文件? 例子:循環中的Ansible循環

postgres: 
    clusters: 
    - name: new 
     configs: 
     - filename: "someconfig.1" 
      template: "path.1" 
     - filename: "someconfig.2" 
      template: "path.2" 
    - name: new2 
     configs: 
     - filename: "someconfig.1" 
      template: "path.1" 
     - filename: "someconfig.2" 
      template: "path.2" 

我想做的事:

- name: Create configs for postgres clusters 
    template: src={{ item.template }} dest={{ cluster.name }}/{{ item.filename }} 
    with_items: item.configs 
    with_items: postgres.clusters as cluster 

回答

0

我的解決辦法:

 
- name: Update configs for clusters 
    sudo: yes 
    sudo_user: postgres 
    tags: 
     - postgres 
     - clusters 
    template: 
     src={{ item.1.template }} 
     dest={{ postgres.config_dir }}/{{ item.0.version|default(postgres.version) }}/{{ item.0.name }}/{{ item.1.filename }} 
     mode={{ item.1.mode|default("0600") }} 
    with_subelements: 
     - postgres.clusters 
     - configs 
    when: item.0.enable|default(true)|bool