ansible / ansible-container

DEPRECATED -- Ansible Container was a tool to build Docker images and orchestrate containers using only Ansible playbooks.
GNU Lesser General Public License v3.0
2.19k stars 393 forks source link

Ignores "when" in service roles #589

Closed borisno2 closed 7 years ago

borisno2 commented 7 years ago
ISSUE TYPE
container.yml
version: "2"
#defaults:
settings:
  conductor_base: ubuntu:xenial

services:
 db:
  from: mysql:5.7
  volumes: 
   - "{{ DOCKER_DATA_ROOT }}/mysql/data:/var/lib/mysql"
  environment:
   MYSQL_ROOT_PASSWORD: "{{ COMMON_MYSQL_MIGRATE_PASS }}"
   MYSQL_DATABASE: "{{ EDXAPP_MYSQL_DB_NAME }}"
   MYSQL_USER: "{{ EDXAPP_MYSQL_USER }}"
   MYSQL_PASSWORD: "{{ EDXAPP_MYSQL_PASSWORD }}"

 mongo:
  from: mongo:3.4
  command: /entrypoint.sh mongod --auth
  volumes:
   - "{{ DOCKER_DATA_ROOT }}/mongo/data:/data/db"
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - mongo_docker

# Need to build our own for ES 0.9
 es:
  from: ubuntu:xenial # opensaas/edx-elasticsearch
  command: ["/usr/share/elasticsearch/bin/elasticsearch","-f"]
  volumes:
   - "{{ DOCKER_DATA_ROOT }}/elasticsearch/data:/data"
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - elasticsearch
   - { role: oraclejdk, tags: ['install:app-requirements'] }

 memcache:
  from: memcached:1.4.24
  volumes:
   - "{{ DOCKER_DATA_ROOT }}/memcache/data:/data"

 nginx:
  from: nginx
  links:
   - lms:lms
   - cms:cms
#   - xqueue:xqueue
   - insights:insights
   - analytics:analytics
  volumes:
   - "{{ DOCKER_DATA_ROOT }}:/edx/var"
  command: |
    /bin/bash -c "nginx -g 'daemon off;'"
  ports:
   - 6080:80
   - 6443:443
   - 18000:18000
   - 18010:18010
   - 18020:18020
   - 18040:18040
   - 18100:18100
   - 18110:18110
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - role: nginx
     nginx_sites:
      - cms
      - lms
      - analytics_api
      - insights
      - lms-preview
      - xqueue
     nginx_default_sites:
      - lms
      - cms

 rabbitmq:
  from: rabbitmq:3.5.3
  volumes:
   - "{{ DOCKER_DATA_ROOT }}/rabbitmq/data:/var/lib/rabbitmq"
  environment:
    RABBITMQ_DEFAULT_USER: "{{ EDXAPP_CELERY_USER }}"
    RABBITMQ_DEFAULT_PASS: "{{ EDXAPP_CELERY_PASSWORD }}"

 forums:
  from: ubuntu:xenial #opensaas/edx-forums
  links:
   - db:db
#   - xqueue:xqueue
   - memcache:memcache
   - mongo:mongo
   - es:es
   - rabbitmq:rabbitmq
  command: ["/edx/app/supervisor/venvs/supervisor/bin/supervisord", "-n", "--configuration", "/edx/app/supervisor/supervisord.conf"]
  depends_on:
    - db
    - memcache
    - mongo
    - es
    - rabbitmq
  volumes:
   - "{{ DOCKER_EDX_ROOT }}/cs_comments_service:/edx/app/forum/cs_comments_service"
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - forum

# xqueue:
#  from: ubuntu:xenial #opensaas/edx-xqueue
#  links:
#   - db:db
#   - memcache:memcache
#   - mongo:mongo
#   - es:es
#   - rabbitmq:rabbitmq
#  command: ["/edx/app/supervisor/venvs/supervisor/bin/supervisord", "-n", "--configuration", "/edx/app/supervisor/supervisord.conf"]
#  volumes:
#   - "{{DOCKER_EDX_ROOT}}/xqueue:/edx/app/edxapp/xqueue"
#   - /dev/log:/dev/log

 lms:
  from: ubuntu:xenial #opensaas/edxapp:trusty-v3
  links:
   - db:db
   - forums:forums
#   - xqueue:xqueue
   - memcache:memcache
   - mongo:mongo
   - es:es
   - rabbitmq:rabbitmq
  command: ["/edx/app/supervisor/venvs/supervisor/bin/supervisord", "-n", "--configuration", "/edx/app/supervisor/supervisord.conf"]
  depends_on:
    - db
    - memcache
    - mongo
    - es
    - rabbitmq
  volumes:
   - "{{ DOCKER_EDX_ROOT }}/edx-platform:/edx/app/edxapp/edx-platform"
   - /dev/log:/dev/log
   - "{{ DOCKER_DATA_ROOT }}/edxapp:/edx/var/edxapp"
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - {role: edxapp, service_variants_enabled: ['lms'], migrate_db: 'no'}

 cms:
  from: ubuntu:xenial #opensaas/edxapp:trusty-v3
  links:
   - db:db
   - forums:forums
#   - xqueue:xqueue
   - memcache:memcache
   - mongo:mongo
   - es:es
   - rabbitmq:rabbitmq
  command: ["/edx/app/supervisor/venvs/supervisor/bin/supervisord", "-n", "--configuration", "/edx/app/supervisor/supervisord.conf"]
  depends_on:
    - db
    - memcache
    - mongo
    - es
    - rabbitmq
  volumes:
   - "{{DOCKER_EDX_ROOT}}/edx-platform:/edx/app/edxapp/edx-platform"
   - /dev/log:/dev/log
   - "{{ DOCKER_DATA_ROOT }}/edxapp:/edx/var/edxapp"
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - { role: 'edxapp', skip_static_remove: True, skip_git: true, service_variants_enabled: ['cms'], migrate_db: 'no' }
   - {role: demo, when: edx_install_demo is defined and edx_install_demo, tags: ['install:configuration', 'migrate']}

 edxworker:
  from: ubuntu:xenial #opensaas/edxapp:trusty-v3
  links:
   - db:db
   - forums:forums
#   - xqueue:xqueue
   - memcache:memcache
   - mongo:mongo
   - es:es
   - rabbitmq:rabbitmq
  command: ["/edx/app/supervisor/venvs/supervisor/bin/supervisord", "-n", "--configuration", "/edx/app/supervisor/supervisord.conf"]
  depends_on:
    - db
    - memcache
    - mongo
    - es
    - rabbitmq
  volumes:
   - "{{DOCKER_EDX_ROOT}}/edx-platform:/edx/app/edxapp/edx-platform"
   - /dev/log:/dev/log 
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - { role: 'edxapp', celery_worker: True, skip_git: true }           

 analytics:
  from: ubuntu:xenial #edxops/trusty-common:v3
  links:
   - db:db
   - forums:forums
#   - xqueue:xqueue
   - memcache:memcache
   - mongo:mongo
   - es:es
   - rabbitmq:rabbitmq
   - insights:insights
  command: ["/edx/app/supervisor/venvs/supervisor/bin/supervisord", "-n", "--configuration", "/edx/app/supervisor/supervisord.conf"]
  depends_on:
    - db
    - memcache
    - mongo
    - es
    - rabbitmq
  volumes:
   - "{{ DOCKER_EDX_ROOT }}/analytics_api:/edx/app/analytics_api"
   - "{{ DOCKER_DATA_ROOT }}/analytics_api:/edx/var/analytics_api"
   - /dev/log:/dev/log
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - analytics_api

 edxconfig:
  from: ubuntu:xenial #edxops/trusty-common:v3
  links:
   - db:db
   - forums:forums
 #  - xqueue:xqueue
   - memcache:memcache
   - mongo:mongo
   - es:es
  command: /bin/false
  depends_on:
    - db
    - memcache
    - mongo
    - es
    - rabbitmq
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - docker_db_setup

 insights:
  from: ubuntu:xenial #opensaas/edx-insights
  links:
   - db:db
   - forums:forums
#   - xqueue:xqueue
   - memcache:memcache
   - mongo:mongo
   - es:es
   - rabbitmq:rabbitmq
  command: ["/edx/app/supervisor/venvs/supervisor/bin/supervisord", "-n", "--configuration", "/edx/app/supervisor/supervisord.conf"]
  depends_on:
    - db
    - memcache
    - mongo
    - es
    - rabbitmq
  volumes:
   - "{{DOCKER_EDX_ROOT}}/insights:/edx/app/insights"
   - /dev/log:/dev/log
   - "{{ DOCKER_DATA_ROOT }}/insights:/edx/var/insights"
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - insights

 analytics_pipeline:
  from: ubuntu:xenial #edxops/trusty-common:v3
  links:
   - db:db
   - forums:forums
#   - xqueue:xqueue
   - memcache:memcache
   - mongo:mongo
   - es:es
   - rabbitmq:rabbitmq
   - insights:insights
  command: |
    /bin/bash su -m hadoop -c /edx/app/hadoop/hadoop/docker-startup.sh
  depends_on:
    - db
    - memcache
    - mongo
    - es
    - rabbitmq
  volumes:
   - "{{ DOCKER_EDX_ROOT }}/hadoop:/edx/app/hadoop"
   - "{{ DOCKER_DATA_ROOT }}/analytics_pipline:/edx/etc/edx-analytics-pipeline"
   - "{{ DOCKER_EDX_ROOT }}/analytics_pipline:/edx/app/edx-analytics-pipeline"
   - "{{ DOCKER_DATA_ROOT }}/hadoop:/edx/var/hadoop"
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - { role: 'hadoop_master', tags: ['install:app-requirements'] }
   - { role: 'hive', tags: ['install:app-requirements'] }
   - { role: 'sqoop', tags: ['install:app-requirements'] }
   - analytics_pipeline 

registries: {}
OS / ENVIRONMENT
Ansible Container, version 0.9.1
Linux, Josh-Ubuntu-PC, 4.10.0-22-generic, #24-Ubuntu SMP Mon May 22 17:43:20 UTC 2017, x86_64
2.7.13 (default, Jan 19 2017, 14:48:08) 
[GCC 6.3.0 20170118] /usr/bin/python
{
  "ContainersPaused": 0, 
  "Labels": null, 
  "CgroupDriver": "cgroupfs", 
  "ContainersRunning": 0, 
  "ContainerdCommit": {
    "Expected": "9048e5e50717ea4497b757314bad98ea3763c145", 
    "ID": "9048e5e50717ea4497b757314bad98ea3763c145"
  }, 
  "InitBinary": "docker-init", 
  "NGoroutines": 22, 
  "Swarm": {
    "ControlAvailable": false, 
    "NodeID": "", 
    "Error": "", 
    "RemoteManagers": null, 
    "LocalNodeState": "inactive", 
    "NodeAddr": ""
  }, 
  "LoggingDriver": "json-file", 
  "OSType": "linux", 
  "HttpProxy": "", 
  "Runtimes": {
    "runc": {
      "path": "docker-runc"
    }
  }, 
  "DriverStatus": [
    [
      "Root Dir", 
      "/var/lib/docker/aufs"
    ], 
    [
      "Backing Filesystem", 
      "extfs"
    ], 
    [
      "Dirs", 
      "290"
    ], 
    [
      "Dirperm1 Supported", 
      "true"
    ]
  ], 
  "OperatingSystem": "Ubuntu 17.04", 
  "Containers": 0, 
  "HttpsProxy": "", 
  "BridgeNfIp6tables": true, 
  "MemTotal": 8350158848, 
  "SecurityOptions": [
    "name=apparmor", 
    "name=seccomp,profile=default"
  ], 
  "Driver": "aufs", 
  "IndexServerAddress": "https://index.docker.io/v1/", 
  "ClusterStore": "", 
  "InitCommit": {
    "Expected": "949e6fa", 
    "ID": "949e6fa"
  }, 
  "Isolation": "", 
  "SystemStatus": null, 
  "OomKillDisable": true, 
  "ClusterAdvertise": "", 
  "SystemTime": "2017-06-08T15:35:36.108970855+10:00", 
  "Name": "Josh-Ubuntu-PC", 
  "CPUSet": true, 
  "RegistryConfig": {
    "InsecureRegistryCIDRs": [
      "127.0.0.0/8"
    ], 
    "IndexConfigs": {
      "docker.io": {
        "Official": true, 
        "Name": "docker.io", 
        "Secure": true, 
        "Mirrors": []
      }
    }, 
    "Mirrors": []
  }, 
  "DefaultRuntime": "runc", 
  "ContainersStopped": 0, 
  "NCPU": 4, 
  "NFd": 16, 
  "Architecture": "x86_64", 
  "KernelMemory": true, 
  "CpuCfsQuota": true, 
  "Debug": false, 
  "ID": "O5PH:4WGS:PSZG:ZNOL:XKD7:6VLD:6OVZ:ZZ5W:TROL:EBL6:XVFB:R2IM", 
  "IPv4Forwarding": true, 
  "KernelVersion": "4.10.0-22-generic", 
  "BridgeNfIptables": true, 
  "NoProxy": "", 
  "LiveRestoreEnabled": false, 
  "ServerVersion": "17.05.0-ce", 
  "CpuCfsPeriod": true, 
  "ExperimentalBuild": false, 
  "MemoryLimit": true, 
  "SwapLimit": false, 
  "Plugins": {
    "Volume": [
      "local"
    ], 
    "Network": [
      "bridge", 
      "host", 
      "macvlan", 
      "null", 
      "overlay"
    ], 
    "Authorization": []
  }, 
  "Images": 65, 
  "DockerRootDir": "/var/lib/docker", 
  "NEventsListener": 0, 
  "CPUShares": true, 
  "RuncCommit": {
    "Expected": "9c2d8d184e5da67c95d601382adf14862e4f2228", 
    "ID": "9c2d8d184e5da67c95d601382adf14862e4f2228"
  }
}
{
  "KernelVersion": "4.10.0-22-generic", 
  "Arch": "amd64", 
  "BuildTime": "2017-05-04T22:10:54.638119411+00:00", 
  "ApiVersion": "1.29", 
  "Version": "17.05.0-ce", 
  "MinAPIVersion": "1.12", 
  "GitCommit": "89658be", 
  "Os": "linux", 
  "GoVersion": "go1.7.5"
}
SUMMARY
STEPS TO REPRODUCE

when tags seam to be ignored when used in roles. In the below example the demo role is installed even when the variable edx_install_demo is not set or is set to false

cms:
  from: ubuntu:xenial #opensaas/edxapp:trusty-v3
  links:
   - db:db
   - forums:forums
#   - xqueue:xqueue
   - memcache:memcache
   - mongo:mongo
   - es:es
   - rabbitmq:rabbitmq
  command: ["/edx/app/supervisor/venvs/supervisor/bin/supervisord", "-n", "--configuration", "/edx/app/supervisor/supervisord.conf"]
  depends_on:
    - db
    - memcache
    - mongo
    - es
    - rabbitmq
  volumes:
   - "{{DOCKER_EDX_ROOT}}/edx-platform:/edx/app/edxapp/edx-platform"
   - /dev/log:/dev/log
   - "{{ DOCKER_DATA_ROOT }}/edxapp:/edx/var/edxapp"
  roles:
   - { role: docker-setup, gather_facts: no }
   - common_vars
   - { role: 'edxapp', skip_static_remove: True, skip_git: true, service_variants_enabled: ['cms'], migrate_db: 'no' }
   - {role: demo, when: edx_install_demo is defined and edx_install_demo, tags: ['install:configuration', 'migrate']}
EXPECTED RESULTS

The demo role should be skipped.

ACTUAL RESULTS

The demo role was installed.

j00bar commented 7 years ago

Howdy, and thank you for the bug report! The --debug build output that's requested would include the resultant playbook in applying that role (see: https://github.com/ansible/ansible-container/blob/1c636ad/container/core.py#L512-L513). It would be immensely helpful to trying to help solve this problem if you could share the build output, especially those debug lines for the role that misbehaved.

@chouseknecht I'm 90% sure the reason this is happening is that the generated playbook doesn't include the variablespace, so no variables are defined for the condition to evaluate. But I'd love to make sure.

borisno2 commented 7 years ago

Thanks @j00bar Full output of build command with debug is here https://gist.github.com/borisno2/692adc04c8874b0a9ffe68d09a5e0325 It looks like, once I fixed up a few things in the role it did in fact skip each individual task within the demo role. I would have expected it to not even look at the role (I think this is what it did previously).

chouseknecht commented 7 years ago

@borisno2

I'm trying to recreate this scenario. Where does edx_install_demo get defined? It's not in the defaults section of container.yml. Is it passed in via --var-file?

drzraf commented 6 years ago

@chouseknecht: same behavior (0.9.2) but specific to import_role/include_role (and conditional applied to meta/main.yml dependencies)