{"action":"opened","issue":{"url":"https://api.github.com/repos/ansible/ansible-container/issues/671","repository_url":"https://api.github.com/repos/ansible/ansible-container","labels_url":"https://api.github.com/repos/ansible/ansible-container/issues/671/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-container/issues/671/comments","events_url":"https://api.github.com/repos/ansible/ansible-container/issues/671/events","html_url":"https://github.com/ansible/ansible-container/issues/671","id":246518386,"number":671,"title":"Using container enabled roles with ansible-container","user":{"login":"mchassy","id":15926092,"avatar_url":"https://avatars2.githubusercontent.com/u/15926092?v=4","gravatar_id":"","url":"https://api.github.com/users/mchassy","html_url":"https://github.com/mchassy","followers_url":"https://api.github.com/users/mchassy/followers","following_url":"https://api.github.com/users/mchassy/following{/other_user}","gists_url":"https://api.github.com/users/mchassy/gists{/gist_id}","starred_url":"https://api.github.com/users/mchassy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mchassy/subscriptions","organizations_url":"https://api.github.com/users/mchassy/orgs","repos_url":"https://api.github.com/users/mchassy/repos","events_url":"https://api.github.com/users/mchassy/events{/privacy}","received_events_url":"https://api.github.com/users/mchassy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-07-29T12:17:22Z","updated_at":"2017-07-29T12:17:22Z","closed_at":null,"body":"##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### container.yml \r\n```\r\nversion: \"2\"\r\nsettings:\r\n  conductor:\r\n    base: \"centos:7\"\r\nservices:\r\n  mongo:\r\n    from: \"centos:7\"\r\n    roles:\r\n    - role: setup_container_role\r\n      which_container: \"mongo\"\r\n    working_dir: \"/opt\"\r\n    user: orson\r\n    entrypoint: [/entrypoint.sh]\r\n    command: [/usr/bin/dumb-init, sleep, infinity]\r\n  tomee:\r\n    from: \"centos:7\"\r\n    roles:\r\n    - role: setup_container_role\r\n      which_container: \"tomee\"\r\n    working_dir: \"/opt\"\r\n    user: orson\r\n    entrypoint: [/entrypoint.sh]\r\n    command: [/usr/bin/dumb-init, sleep, infinity]\r\n\r\nregistries:\r\n  docker:\r\n    url: https://index.docker.io/v1/\r\n    # url: https://cloud.docker.com/api/app/v1/service/\r\n    namespace: orsontestdata\r\n  # Add optional registries used for deployment. For example:\r\n  #  google:\r\n  #    url: https://gcr.io\r\n  #    namespace: my-cool-project-xxxxxx\r\n\r\n```\r\n\r\n##### OS / ENVIRONMENT\r\n<!--- Paste output from `ansible-container --debug version` between the quotes below -->\r\n```\r\n$ ansible-container --debug version\r\nAnsible Container, version 0.9.2rc0\r\nDarwin, MMac.local, 16.6.0, Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64, x86_64\r\n2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39)\r\n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] /Users/markchassy/ansible/bin/python\r\n{\r\n  \"ContainersPaused\": 0,\r\n  \"Labels\": null,\r\n  \"CgroupDriver\": \"cgroupfs\",\r\n  \"ContainersRunning\": 0,\r\n  \"ContainerdCommit\": {\r\n    \"Expected\": \"cfb82a876ecc11b5ca0977d1733adbe58599088a\",\r\n    \"ID\": \"cfb82a876ecc11b5ca0977d1733adbe58599088a\"\r\n  },\r\n  \"InitBinary\": \"docker-init\",\r\n  \"NGoroutines\": 30,\r\n  \"Swarm\": {\r\n    \"ControlAvailable\": false,\r\n    \"NodeID\": \"\",\r\n    \"Error\": \"\",\r\n    \"RemoteManagers\": null,\r\n    \"LocalNodeState\": \"inactive\",\r\n    \"NodeAddr\": \"\"\r\n  },\r\n  \"LoggingDriver\": \"json-file\",\r\n  \"OSType\": \"linux\",\r\n  \"HttpProxy\": \"\",\r\n  \"Runtimes\": {\r\n    \"runc\": {\r\n      \"path\": \"docker-runc\"\r\n    }\r\n  },\r\n  \"DriverStatus\": [\r\n    [\r\n      \"Root Dir\",\r\n      \"/var/lib/docker/aufs\"\r\n    ],\r\n    [\r\n      \"Backing Filesystem\",\r\n      \"extfs\"\r\n    ],\r\n    [\r\n      \"Dirs\",\r\n      \"21\"\r\n    ],\r\n    [\r\n      \"Dirperm1 Supported\",\r\n      \"true\"\r\n    ]\r\n  ],\r\n  \"OperatingSystem\": \"Alpine Linux v3.5\",\r\n  \"Containers\": 0,\r\n  \"HttpsProxy\": \"\",\r\n  \"BridgeNfIp6tables\": true,\r\n  \"MemTotal\": 4139130880,\r\n  \"SecurityOptions\": [\r\n    \"name=seccomp,profile=default\"\r\n  ],\r\n  \"Driver\": \"aufs\",\r\n  \"IndexServerAddress\": \"https://index.docker.io/v1/\",\r\n  \"ClusterStore\": \"\",\r\n  \"InitCommit\": {\r\n    \"Expected\": \"949e6fa\",\r\n    \"ID\": \"949e6fa\"\r\n  },\r\n  \"Isolation\": \"\",\r\n  \"SystemStatus\": null,\r\n  \"OomKillDisable\": true,\r\n  \"ClusterAdvertise\": \"\",\r\n  \"SystemTime\": \"2017-07-29T11:46:06.483740859Z\",\r\n  \"Name\": \"moby\",\r\n  \"CPUSet\": true,\r\n  \"RegistryConfig\": {\r\n    \"AllowNondistributableArtifactsCIDRs\": [],\r\n    \"Mirrors\": [],\r\n    \"IndexConfigs\": {\r\n      \"docker.io\": {\r\n        \"Official\": true,\r\n        \"Name\": \"docker.io\",\r\n        \"Secure\": true,\r\n        \"Mirrors\": []\r\n      }\r\n    },\r\n    \"AllowNondistributableArtifactsHostnames\": [],\r\n    \"InsecureRegistryCIDRs\": [\r\n      \"127.0.0.0/8\"\r\n    ]\r\n  },\r\n  \"DefaultRuntime\": \"runc\",\r\n  \"ContainersStopped\": 0,\r\n  \"NCPU\": 4,\r\n  \"NFd\": 18,\r\n  \"Architecture\": \"x86_64\",\r\n  \"KernelMemory\": true,\r\n  \"CpuCfsQuota\": true,\r\n  \"Debug\": true,\r\n  \"ID\": \"AC3E:EYB4:UGTT:FYMR:33IQ:ACRY:ZNCO:EK6S:HHK4:OBMR:3RCV:PWSL\",\r\n  \"IPv4Forwarding\": true,\r\n  \"KernelVersion\": \"4.9.36-moby\",\r\n  \"BridgeNfIptables\": true,\r\n  \"NoProxy\": \"*.local, 169.254/16\",\r\n  \"LiveRestoreEnabled\": false,\r\n  \"ServerVersion\": \"17.06.0-ce\",\r\n  \"CpuCfsPeriod\": true,\r\n  \"ExperimentalBuild\": true,\r\n  \"MemoryLimit\": true,\r\n  \"SwapLimit\": true,\r\n  \"Plugins\": {\r\n    \"Volume\": [\r\n      \"local\"\r\n    ],\r\n    \"Network\": [\r\n      \"bridge\",\r\n      \"host\",\r\n      \"ipvlan\",\r\n      \"macvlan\",\r\n      \"null\",\r\n      \"overlay\"\r\n    ],\r\n    \"Authorization\": null,\r\n    \"Log\": [\r\n      \"awslogs\",\r\n      \"fluentd\",\r\n      \"gcplogs\",\r\n      \"gelf\",\r\n      \"journald\",\r\n      \"json-file\",\r\n      \"logentries\",\r\n      \"splunk\",\r\n      \"syslog\"\r\n    ]\r\n  },\r\n  \"Images\": 20,\r\n  \"DockerRootDir\": \"/var/lib/docker\",\r\n  \"NEventsListener\": 1,\r\n  \"CPUShares\": true,\r\n  \"RuncCommit\": {\r\n    \"Expected\": \"2d41c047c83e09a6d61d464906feb2a2f3c52aa4\",\r\n    \"ID\": \"2d41c047c83e09a6d61d464906feb2a2f3c52aa4\"\r\n  }\r\n}\r\n{\r\n  \"KernelVersion\": \"4.9.36-moby\",\r\n  \"Arch\": \"amd64\",\r\n  \"BuildTime\": \"2017-06-23T21:51:55.152028673+00:00\",\r\n  \"ApiVersion\": \"1.30\",\r\n  \"Version\": \"17.06.0-ce\",\r\n  \"MinAPIVersion\": \"1.12\",\r\n  \"GitCommit\": \"02c1d87\",\r\n  \"Os\": \"linux\",\r\n  \"Experimental\": true,\r\n  \"GoVersion\": \"go1.8.3\"\r\n}\r\n```\r\n##### SUMMARY\r\nI am working on a common deployment of my application both for VM installs and container installs. I have the VM ansible script tested and working. In the VM deployment, I have a common setup role which executes as root. Then I have separate roles for mongo and tomee which are executed by the application user which is created by the initial setup role. \r\n\r\nThere is one tomee specific action in the setup, which is the install of the right version of java. I do this in the setup role, because you need to be root to install java.\r\n\r\nI would like to do the same thing in container deployment. This means I would run the setup role for each container. I would pass the name of the container as a variable, so that for the tomee container, java would be installed. Also, I need to execute container specific actions for the mongo and tomee roles.\r\n\r\nFrom the documentation, I understood 2 things about roles and container enabled roles.\r\n* Any tasks in meta/container.yml will be executed in addition to task in tasks/main.yml\r\n* I can pass a parameter to a role\r\n\r\nSo I have create a very simple role which basically create 4 files. \r\n\r\nIn the main.yml I create 2 files\r\n- one which is always created\r\n- one which is always created with the name of the container which I passed as a parameter\r\n\r\nIn the meta/container.yml I create 2 files\r\n- one which should always be created if the role is run with ansible-container\r\n- one which should always be created if the role is run with ansible-container with the name of the container which I passed as a parameter\r\n\r\n\r\n\r\n##### STEPS TO REPRODUCE\r\n\r\n```\r\nansible-container build\r\n```\r\n\r\n<!--- You can also paste gist.github.com links for larger files -->\r\n\r\n##### EXPECTED RESULTS\r\n- 2 containers: orson-tomee and orson-mongo\r\n- each should contain 4 files in /home/orson\r\n- 2 of those files should be created with name of the container which was passed as a parameter\r\n\r\n##### ACTUAL RESULTS\r\n- The tasks in meta/container.yml are never executed, so only 2 files are created\r\n- The named file is called mongo\r\n- The roles executes twice, but only one container is built. The same container is create with 2 tags. One for mongo and one for tomee. \r\n\r\nHere is setup_container_role/tasks/main.yml\r\n\r\n```\r\n---\r\n- name: Install dumb init\r\n  get_url:\r\n    dest: /usr/bin/dumb-init\r\n    url: https://github.com/Yelp/dumb-init/releases/download/v1.0.2/dumb-init_1.0.2_amd64\r\n    mode: 0775\r\n    validate_certs: no\r\n- name: Make orson group\r\n  group: name=orson state=present\r\n- name: Make orson user\r\n  user: name=orson state=present createhome=yes home=/home/orson/ uid=1000 group=orson\r\n- name: I do this all the time\r\n  file: path=/home/orson/allthetime.txt state=touch mode=0777\r\n- name: I do this based on a variable\r\n  file: path=\"/home/orson/{{ which_container }}.txt\" state=touch mode=0777\r\n- name: place entrypoint template\r\n  template: src=entrypoint.sh dest=/entrypoint.sh mode=0777\r\n\r\n```\r\nHere is setup_container_role/meta/container.yml\r\n\r\n```\r\n---\r\n- name: I do this when I am a container\r\n  file: path=/home/orson/containertime.txt state=touch mode=0777\r\n- name: I do this when I am a container, based on a variable\r\n  file: path=\"/home/orson/container_{{ which_container }}.txt\" state=touch mode=0777\r\n\r\n```\r\n\r\nHere you can see that the same container was simply tagged as mongo and tomee\r\n```\r\n$ docker images\r\nREPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE\r\norson-mongo                 20170729114110      9b3f3e004d42        35 minutes ago      193MB\r\norson-mongo                 latest              9b3f3e004d42        35 minutes ago      193MB\r\norson-tomee                 latest              9b3f3e004d42        35 minutes ago      193MB\r\norson-conductor             latest              e1a4800b1090        35 minutes ago      553MB\r\n```"}}
{"actor":{"display_login":"mchassy"}}