Open HontoNoRoger opened 7 years ago
@HontoNoRoger
Thank your for your interest in Ansible Container! We appreciate the time you've taken to try it, and to open an issue.
I'm labeling this as a question
, simply because it's not really a bug. Maybe it could become an enhancement. What I mean is that, --roles-path
is the intended vehicle for enabling users to bring their own roles into the build container without copying them to ansible/roles
within the project.
I believe that adding a roles_path
to ansible.cfg is not working, because the specified paths need to be available inside the build container. In other words /home/roger/aws/ansible/roles
, has to be made available as a volume in the build container. You could do that using --with-volumes
, and specifying roles_path
in ansible.cfg, but --roles-path
is the shortcut.
Hopefully my explanation makes sense. If not, please let me know. Also, if you feel that this is not clear in our documentation, please share your thoughts there as well. Perhaps we need to document this better.
@chouseknecht Oh I see, so basically Ansible Container automatically provides the roles (usually in the configuration directory) to the container and executes it locally (i.e. in the container itself, not from the outside). Without using the shortcut --roles-path
or the default path in my Ansible Container configuration directory, the roles won't be available inside the container and therefore can't be found, right?
I'm still a little bit confused, reading the getting started I got the idea that Ansible Container would simply run Ansible from outside the container with a generated inventory file based on the container.yml. So I didn't see the need of actually making my roles available inside the containers.
Changing this from "question" to "documentation" for potential docs enhancement.
hi @chouseknecht - referring to your reply above, this doesn't work for me.
I have a directory structure which looks like this :
├── Ansible │ |── group_vars │ ├── host_vars │ ├── inventories │ └── roles ├── Containers │ ├── Ansible-Container │ ├── Docker-Compose │ └── Dockerfiles
The Ansible Container projects are in the Containers/Ansible-Container part while the roles are in Ansible/roles path.
In one of my Ansible Container projects, I want to use roles from the local filesystem, by passing --roles-path
, like this :
ansible-container --engine docker --debug build --roles-path /home/becker/Ops/AAROC/DevOps/Ansible/roles/
However, that gives an error saying that the role that I want in the container.yml
cannot be found
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 341, in conductor_commandline
conductor_config = AnsibleContainerConductorConfig(containers_config)
File "/_ansible/container/__init__.py", line 19, in __wrapped__
return fn(*args, **kwargs)
File "/_ansible/container/config.py", line 222, in __init__
self._process_services()
File "/_ansible/container/config.py", line 285, in _process_services
role_metadata = get_metadata_from_role(role_name)
File "/_ansible/container/__init__.py", line 19, in __wrapped__
return fn(*args, **kwargs)
File "/_ansible/container/utils/__init__.py", line 257, in get_metadata_from_role
return get_content_from_role(role_name, os.path.join('meta', 'container.yml'))
File "/_ansible/container/__init__.py", line 19, in __wrapped__
return fn(*args, **kwargs)
File "/_ansible/container/utils/__init__.py", line 246, in get_content_from_role
role_path = resolve_role_to_path(role_name)
File "/_ansible/container/__init__.py", line 19, in __wrapped__
return fn(*args, **kwargs)
File "/_ansible/container/utils/__init__.py", line 198, in resolve_role_to_path
loader=loader)
File "/usr/lib/python2.7/site-packages/ansible/playbook/role/include.py", line 59, in load
return ri.load_data(data, variable_manager=variable_manager, loader=loader)
File "/usr/lib/python2.7/site-packages/ansible/playbook/base.py", line 241, in load_data
ds = self.preprocess_data(ds)
File "/usr/lib/python2.7/site-packages/ansible/playbook/role/definition.py", line 94, in preprocess_data
(role_name, role_path) = self._load_role_path(role_name)
File "/usr/lib/python2.7/site-packages/ansible/playbook/role/definition.py", line 187, in _load_role_path
raise AnsibleError("the role '%s' was not found in %s" % (role_name, ":".join(role_search_paths)), obj=self._ds)
ansible.errors.AnsibleError: the role 'CODE-RADE-container' was not found in ./roles:/src/roles:/etc/ansible/roles:.
This role is definitely in the roles-path
I asked for.
What gives ?
@brucellino
I assume you're using the latest Ansible Container installed via pip. If so there is a bug, and --roles-path
is being ignored. See #449. This is now fixed. To get the update, you'll need to run from source.
I'd prefer that roles_path
defined in ansible.cfg
work if it's specified. From a users point of view, I'd like to checkin the custom path to my roles relative to wherever the ansible.cfg
lives in my repository. From an implementation point of view, ansible-container
could inspect ansible.cfg
to see if roles_path
is specified and if so, do the same behavior that is being done with --roles-path
specified on the command line. I also think that if both are specified, the --roles-path
from the command line would take precedence.
ISSUE TYPE
container.yml
main.yml
OS / ENVIRONMENT
SUMMARY
Currently, the custom role path only works with --roles-path when executing an
ansible-container build
command, not with overwriting theroles_path
inansible.cfg
.STEPS TO REPRODUCE
ansible-container init
for general configuration.ansible.cfg
, put something like:sudo ansible-container build
EXPECTED RESULTS
The same as with
sudo ansible-container build --roles-path /home/roger/aws/ansible/roles
which is:ACTUAL RESULTS
Role can't be found despite having the proper path at the end of the used configuration.