{"action":"created","issue":{"url":"https://api.github.com/repos/metacloud/molecule/issues/535","repository_url":"https://api.github.com/repos/metacloud/molecule","labels_url":"https://api.github.com/repos/metacloud/molecule/issues/535/labels{/name}","comments_url":"https://api.github.com/repos/metacloud/molecule/issues/535/comments","events_url":"https://api.github.com/repos/metacloud/molecule/issues/535/events","html_url":"https://github.com/metacloud/molecule/issues/535","id":181124108,"number":535,"title":"[question] Any chance to support docker for mac","user":{"login":"milosgajdos83","id":1392526,"avatar_url":"https://avatars.githubusercontent.com/u/1392526?v=3","gravatar_id":"","url":"https://api.github.com/users/milosgajdos83","html_url":"https://github.com/milosgajdos83","followers_url":"https://api.github.com/users/milosgajdos83/followers","following_url":"https://api.github.com/users/milosgajdos83/following{/other_user}","gists_url":"https://api.github.com/users/milosgajdos83/gists{/gist_id}","starred_url":"https://api.github.com/users/milosgajdos83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milosgajdos83/subscriptions","organizations_url":"https://api.github.com/users/milosgajdos83/orgs","repos_url":"https://api.github.com/users/milosgajdos83/repos","events_url":"https://api.github.com/users/milosgajdos83/events{/privacy}","received_events_url":"https://api.github.com/users/milosgajdos83/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/metacloud/molecule/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-05T11:05:32Z","updated_at":"2016-10-11T14:03:21Z","closed_at":"2016-10-09T01:38:44Z","body":"Default provisioner in `molecule` is `Vagrant`, however a lot of developers nowadays use `docker` for Mac, which runs `docker` daemon in a small virtual machine as oppose to more full blown `Vagrant` VM.\r\n\r\nSome of our `Ansible` roles  merely spin `docker` containers like this:\r\n\r\n```\r\n- name: create nginx proxy container\r\n  docker:\r\n    name: nginx\r\n    image: \"nginx\"\r\n    pull: always\r\n    state: started\r\n    volumes:\r\n      - \"{{ nginx_conf }}:/etc/nginx/conf.d/default.conf:ro\"\r\n    ports:\r\n      - \"{{ nginx_port }}:{{ nginx_port }}\"\r\n    restart_policy: always\r\n  tags: ['nginx']\r\n```\r\n\r\nI wonder if you have any plans to add support for `docker` for Mac or even better, we could do simply with \"local\" `Ansible` testing without spinning any extra VMs."},"comment":{"url":"https://api.github.com/repos/metacloud/molecule/issues/comments/252925947","html_url":"https://github.com/metacloud/molecule/issues/535#issuecomment-252925947","issue_url":"https://api.github.com/repos/metacloud/molecule/issues/535","id":252925947,"user":{"login":"milosgajdos83","id":1392526,"avatar_url":"https://avatars.githubusercontent.com/u/1392526?v=3","gravatar_id":"","url":"https://api.github.com/users/milosgajdos83","html_url":"https://github.com/milosgajdos83","followers_url":"https://api.github.com/users/milosgajdos83/followers","following_url":"https://api.github.com/users/milosgajdos83/following{/other_user}","gists_url":"https://api.github.com/users/milosgajdos83/gists{/gist_id}","starred_url":"https://api.github.com/users/milosgajdos83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milosgajdos83/subscriptions","organizations_url":"https://api.github.com/users/milosgajdos83/orgs","repos_url":"https://api.github.com/users/milosgajdos83/repos","events_url":"https://api.github.com/users/milosgajdos83/events{/privacy}","received_events_url":"https://api.github.com/users/milosgajdos83/received_events","type":"User","site_admin":false},"created_at":"2016-10-11T14:03:21Z","updated_at":"2016-10-11T14:03:21Z","body":"Hi, I'm sorry for late update. Unfortunately I was swamped doing some other work.\r\n\r\nThe example you mentioned in your comment is quite nice indeed, but it does not cover testing of the role that set up containers itself. Let me explain what I mean by that. \r\n\r\nThe example you posted shows how you can provision the docker containers **inside which** you can test your roles. This is pretty handy for roles which do not set up containers themselves. Roles that basically do stuff outside the containers like setting up configuration files and installing packages. Some of our Ansible create containers using Ansible `docker` module and the container container set up depends on Ansible role variables -- these variables are different in different environments. Let me give you two examples that will illustrate what I'm saying.\r\n\r\nTraditiona Ansible role which does not set up any containers in its task list. That is how we test our zookeeper -- which doesn't run in a container but rather directly on a VM. We can test our `zookeeper` role using the Docker driver that you linked me to like this. Our `molecule.yml` looks like this (it uses Docker driver):\r\n\r\n```\r\n---\r\nansible:\r\n  playbook: playbook.yml\r\n\r\ndocker:\r\n  containers:\r\n  - name: zk01\r\n    ansible_groups:\r\n      - zk_cluster\r\n    image: centos\r\n    image_version: \"7.2.1511\"\r\n    privileged: True\r\n    port_bindings:\r\n      2181: 2181\r\n      2888: 2888\r\n      3888: 3888\r\n```\r\n\r\nNow, the tests are derived from `playbook.yml` which looks like this;\r\n\r\n```\r\n---\r\n- hosts: all\r\n  pre_tasks:\r\n    - name: \"Get zk01 IP address\"\r\n      local_action: command docker inspect --format {% raw %}'{{ .NetworkSettings.IPAddress }}'{% endraw %} zk01\r\n      register: zk01_ip\r\n      become: false\r\n      changed_when: zk01_ip.rc == 12\r\n\r\n  vars:\r\n    zk_hosts:\r\n      - host: \"{{ zk01_ip.stdout }}\"\r\n        id: 1\r\n\r\n  roles:\r\n    - role: ansible-zookeeper\r\n```\r\n\r\nThis is awesome. `molecule.yml` allows to set up a Docker container inside which `ansible-zookeeper` role is run and tested.\r\n\r\n** ANSIBLE ROLE THAT SPINS UP DOCKER CONTAINERS**\r\n\r\nTake the **following example of a different Ansible role** whose main tasks look like this `ansible-docker-nginx/tasks/main.yml`:\r\n\r\n```\r\n- name: create nginx proxy\r\n  docker:\r\n    name: nginx-proxy\r\n    image: \"nginx\"\r\n    pull: always\r\n    state: started\r\n    log_driver: syslog\r\n    log_opt:\r\n      tag: docker,{{ '{{' }}.ImageID{{ '}}' }},{{ '{{' }}.ImageName{{ '}}' }},{{ '{{' }}.ID{{ '}}' }}\r\n    volumes:\r\n      - \"{{ nginx_conf }}:/etc/nginx/conf.d/default.conf:ro\"\r\n    ports:\r\n      - \"{{ nginx_port }}:{{ nginx_port }}\"\r\n    restart_policy: always\r\n  tags: ['nginx-proxy']\r\n```\r\n\r\nThis is a task defined in `main.yml` of `ansible-docker-nginx` role. We can't test this role unless we spin up a docker in a docker or use `Vagrant` provider. Your suggestion was to look at the Docker **provider**, but we can't use this provider to test the role for different variables like `{{ nginx_conf }}` etc. because the provider does not extrapolate Ansible variables for a particular tested role -- that's done in `playbook.yml` not in `molecule.yml`. \r\n\r\nOur options are : we could generate a few `molecule.yml` files for different configurations and then parameterize the tests but that's the way down the rabbit hole of combinatorial explosion of all possible files. Or we could use `Vagrant` provider, but I find it hard to justify to run another VM on my laptop :-/\r\n\r\nWhat would be awesome is to have something like `Vagrant` driver, but instead of vagrant we would use the Docker on Mac. So our `playbook.yml` to test the `ansible-docker-nginx` role could look like this:\r\n\r\n```\r\n---\r\n- hosts: all\r\n  vars:\r\n    nginx_port: 8080\r\n    nginx_conf: \"/opt/nginx.conf\"\r\n  roles:\r\n    - role: ansible-docker-nginx\r\n```\r\n\r\nBoom! This would give us again, same self-contained, test just like in the first `zookeeper` role example at the beginning."}}
{"actor":{"display_login":"milosgajdos83"}}