ansible-container
ansible-container copied to clipboard
handle roles with multiple directory levels?
ISSUE TYPE
- Bug Report
container.yml
version: '2'
settings:
project_name: testproject
conductor:
base: 'centos:7'
roles_path:
- <redacted>
- roles/
services:
testservice:
from: <redacted>
roles:
- BuildBox/Base
working_dir: /tmp
ports:
- '22'
command:
- /usr/bin/sshd
- -D
OS / ENVIRONMENT
$ ansible-container --debug version
Ansible Container, version 0.9.3rc0
Linux, ubuntu, 4.4.0-101-generic, #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017, x86_64
2.7.12 (default, Nov 20 2017, 18:23:56)
[GCC 5.4.0 20160609] /home/ubuntu/ansible-container/bin/python2
using virtualenv, ansible-container installed from github repo checkout from 2017-12-13
SUMMARY
The role name is used as a portion of a constructed container name. If the role is organized in a directory structure with two levels, a slash becomes part of the container name (the '/' is not valid).
I have not determined a workaround that leaves the roles intact. I read over the ansible docs best practices on roles; the examples show a role as a single directory level, and there is no advice given to use only one directory level.
In the example shown below, the role is 'BuildBox/Base'.
STEPS TO REPRODUCE
build normally
EXPECTED RESULTS
successful build
ACTUAL RESULTS
note container name at end of output cited below (--debug not used as it is not necessary to demonstrate situation):
# ansible-container build
Building Docker Engine context...
Starting Docker build of Ansible Container Conductor image (please be patient)...
Parsing conductor CLI args.
Docker™ daemon integration engine loaded. Build starting. project=testproject
Building service... project=testproject service=testservice
Fingerprint for this layer: b73605e439fcbf8ab41e434d5bfb3c7f447a4705c322275b82d251da67f9cc89 parent_fingerprint=636905ad79799a2d76c94e240027f7e456bfd368773492e7ccc1bc49c05e8be1 parent_image_id=sha256:48599bf1cbc02a62ed2f45f648967f38df4e8fbea0699c26cb98360229da934e role=BuildBox/Base service=testservice
Cached layer for for role BuildBox/Base not found or invalid. cur_image_id=sha256:48599bf1cbc02a62ed2f45f648967f38df4e8fbea0699c26cb98360229da934e fingerprint=b73605e439fcbf8ab41e434d5bfb3c7f447a4705c322275b82d251da67f9cc89 service=testservice
Could not locate intermediate build container to reapply role BuildBox/Base. Applying role on image sha256:48599bf1cbc02a62ed2f45f648967f38df4e8fbea0699c26cb98360229da934e as container testproject_testservice-636905ad-BuildBox/Base. cur_image_fingerprint=636905ad79799a2d76c94e240027f7e456bfd368773492e7ccc1bc49c05e8be1 service=testservice
Traceback (most recent call last):
File "/usr/bin/conductor", line 11, in <module>
load_entry_point('ansible-container', 'console_scripts', 'conductor')()
File "/_ansible/container/__init__.py", line 19, in __wrapped__
return fn(*args, **kwargs)
File "/_ansible/container/cli.py", line 410, in conductor_commandline
**params)
File "/_ansible/container/__init__.py", line 19, in __wrapped__
return fn(*args, **kwargs)
File "/_ansible/container/core.py", line 893, in conductorcmd_build
local_python=local_python
File "/_ansible/container/core.py", line 802, in _run_intermediate_build_container
**run_kwargs)
File "/_ansible/container/docker/engine.py", line 106, in __wrapped__
return fn(self, *args, **kwargs)
File "/_ansible/container/__init__.py", line 19, in __wrapped__
return fn(*args, **kwargs)
File "/_ansible/container/docker/engine.py", line 274, in run_container
**run_kwargs
File "/usr/lib/python2.7/site-packages/docker/models/containers.py", line 715, in run
detach=detach, **kwargs)
File "/usr/lib/python2.7/site-packages/docker/models/containers.py", line 766, in create
resp = self.client.api.create_container(**create_kwargs)
File "/usr/lib/python2.7/site-packages/docker/api/container.py", line 449, in create_container
return self.create_container_from_config(config, name)
File "/usr/lib/python2.7/site-packages/docker/api/container.py", line 460, in create_container_from_config
return self._result(res, True)
File "/usr/lib/python2.7/site-packages/docker/api/client.py", line 228, in _result
self._raise_for_status(response)
File "/usr/lib/python2.7/site-packages/docker/api/client.py", line 224, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/usr/lib/python2.7/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 500 Server Error: Internal Server Error ("Invalid container name (testproject_testservice-636905ad-BuildBox/Base), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed")
Conductor terminated. Cleaning up. command_rc=1 conductor_id=79308179688b614cc73a66b6f8da562300c13ce03dba9452adae52d6e92e3d43 save_container=False
ERROR Conductor exited with status 1
Have you tried dot-notation for roles, e.g. BuildBox.Base?
Re: dot-notation, do you mean using a dot in the container.yml file, or actually reorganizing the roles directory structure so that it is single-level, and to use a dot in the directory name? For the former, this results in error
ansible.errors.AnsibleError: the role 'BuildBox.Base' was not found in <redacted roles path>
Note this problem does not exist in 0.9.2 (installed via pip), and exists in 0.9.3rc0 (both git checkout at 2017-12-13 commit 6eeb44a110c3d79d3a837b7f0e41754c82541ffe and checkout today commit bec928eafdba3e13bdc30888a10dc3458d4c7bd4).