2017-06-27 7 views
0

今日、私は私はすべての私のコンテナ名のリストが含まれている余分な変数{{ RCD_APIS }}を持つ複数のドッキングウィンドウコンテナ ansibleは - に応じて、VARの値を定義する別の変数

- name: start container current 
     docker_container: 
     name: "{{ item.name }}" 
     image: "{{ item.name }}:{{ item.version }}" 
     state: started 
     recreate: true 
     ports: 
      - "{{ item.ports }}" 
     volumes: 
      - /opt/application/i99/{{ item.type }}/logs:/opt/application/i99/{{ item.type }}/logs 
     env_file: /opt/application/i99/{{ item.type }}/{{ item.name }}/{{ item.name }}-PreProd-config.list 
     env: 
      LOG_FILE_WS: "/opt/application/i99/{{ item.type }}/logs/{{ hostname }}_WS.log" 
     with_items:  
     - { name: 'backend', ports: '8000:8000', type: 'current', version: '{{RCD_VERSION_CURRENT}}' } 
     - { name: 'connecteur', ports: '8400:8400', type: 'current', version: '{{RCD_VERSION_CURRENT}}' } 
     - { name: 'api-alerting', ports: '8100:8100', type: 'current', version: '{{RCD_VERSION_CURRENT}}' } 
     - { name: 'api-tracking', ports: '8200:8200', type: 'current', version: '{{RCD_VERSION_CURRENT}}' } 

を開始することを可能にするループを持っています。 Iそのリストをループしたいと名前にconditionnally次の変数を定義して、コンテナに定義する

VARS実行します:ポート、タイプ、バージョン

私は

- name: start container current 
     docker_container: 
     name: "{{ item }}" 
     image: "{{ item }}:{{ version }}" 
     state: started 
     user: adi99api 
     recreate: true 
     ports: 
      - "{{ ports }}" 
     volumes: 
      - /opt/application/i99/{{ type }}/logs:/opt/application/i99/{{ type }}/logs 
     env_file: /opt/application/i99/{{ type }}/{{ item }}/{{ name }}-PreProd-config.list 
     env: 
      LOG_FILE_WS: "/opt/application/i99/{{ type }}/logs/{{ hostname }}_WS.log" 
    with_items: "{{ RCD_APIS.split(',') }}" 
    when: (item == "backend", ports: '8000:8000', type: 'current', version: '{{RCD_VERSION_CURRENT}}') or 
      (item == "connecteur", ports: '8400:8400', type: 'pilote', version: '{{RCD_VERSION_PILOTE}}') 

答えて

0
ような何かをしたいが
# in a vars file, or a `vars` section 
--- 
docker_containers_config: 
    backend: 
    ports: '8000:8000' 
    type: current 
    version: '{{RCD_VERSION_CURRENT}}' 
    connecteur: 
    ports: '8400:8400' 
    type: current 
    version: '{{RCD_VERSION_CURRENT}}' 
    api-alerting: 
    ports: '8100:8100' 
    type: 'current' 
    version: '{{RCD_VERSION_CURRENT}}' 
    api-tracking: 
    ports: '8200:8200' 
    type: 'current' 
    version: '{{RCD_VERSION_CURRENT}}' 

_

# In your tasks 
- name: start container current 
    docker_container: 
    name: "{{ item }}" 
    image: "{{ item }}:{{ docker_containers_config[item].version }}" 
    state: started 
    recreate: true 
    ports: 
     - "{{ docker_containers_config[item].ports }}" 
    volumes: 
     - /opt/application/i99/{{ item.type }}/logs:/opt/application/i99/{{ item.type }}/logs 
    env_file: /opt/application/i99/{{ docker_containers_config[item].type }}/{{ item }}/{{ item }}-PreProd-config.list 
    env: 
     LOG_FILE_WS: "/opt/application/i99/{{ docker_containers_config[item].type }}/logs/{{ hostname }}_WS.log" 
    with_items: "{{ RCD_APIS.split(',') }}" 
関連する問題