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 394 forks source link

"The role was not found" and "Failed to load container.yml" errors #963

Open mac89 opened 5 years ago

mac89 commented 5 years ago
ISSUE TYPE
container.yml
version: "2"
settings:

  conductor:
    # The Conductor container does the heavy lifting, and provides a portable
    # Python runtime for building your target containers. It should be derived
    # from the same distribution as you're building your target containers with.
    base: centos:7
    # volumes:      # Provide a list of volumes to mount
    # environment:  # List or mapping of environment variables

  # Set the name of the project. Defaults to basename of the project directory.
  # For built services, concatenated with service name to form the built image name.
  project_name: demo

  # The deployment_output_path is mounted to the Conductor container, and the
  # `run` and `deployment` commands then write generated Ansible playbooks to it.
  # deployment_output_path: ./ansible-deployment

  # When using the k8s or openshift engines, use the following to authorize with the API.
  # Values set here will be passed to the Ansible modules. Any file paths will be mounted
  # to the conductor container, allowing the `run` command to access the API.
  #k8s_auth:
    # path to a K8s config file
    #config_file:
    # name of a context found within the config file
    #context:
    # URL for accessing the K8s API
    #host:
    # An API authentication token
    #api_key:
    # Path to a ca cert file
    #ssl_ca_cert:
    # Path to a cert file
    #cert_file:
    # Path to a key file
    #key_file:
    # boolean, indicating if SSL certs should be validated
    #verify_ssl:

  # When using the k8s or openshift engines, use the following to set the namespace.
  # If not set, the project name will be used. For openshift, the namespace maps to a project,
  # and description and display_name are supported.
  #k8s_namespace:
  #  name:
  #  description:
  #  display_name:

services:
  # Add your containers here, specifying the base image you want to build from.
  # To use this example, uncomment it and delete the curly braces after services key.
  # You may need to run `docker pull ubuntu:trusty` for this to work.

   web:
     from: "centos:7"
     roles:
       - role: flask
  #   ports:
  #     - "80:80"
  #   command: ["systemctl daemon-reload"]
  #   dev_overrides:
  #     environment:
  #       - "DEBUG=1"
registries: {}
  # Add optional registries used for deployment. For example:
  #  google:
  #    url: https://gcr.io
  #    namespace: my-cool-project-xxxxxx
OS / ENVIRONMENT
Windows 10
Docker version 18.06.0-ce, build 0ffa825
Ansible/Ansible-container running in Docker image `mac89/ansible-container`
SUMMARY

I get the following error the role 'flask' was not found in ./roles:/src/roles:/etc/ansible/roles: when attempting to build the container from within my Docker image mac89/ansible-container. I suspect it has something to do with my running ansible-container from within a Docker image, but I have no idea how to solve it.

Using the steps described here I can use external roles: https://hub.docker.com/r/mac89/ansible-container/

However I cannot use ansible-container install which results in the error container.exceptions.AnsibleContainerGalaxyFatalException: Failed to load container.yml: [Errno 2] No such file or directory: '/src/con tainer.yml'

STEPS TO REPRODUCE

You can reproduce by using my Docker image and adding the volume mapping /var/run/docker.sock:/var/run/docker.sock and executing the commands below.

docker exec -it YOUR_CONTAINER_ID bash
mkdir demo
cd demo
ansible-container init
pico container.yml (add flask role)
ansible-container build
EXPECTED RESULTS

The role to be found and the container to build

ACTUAL RESULTS
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 389, in conductor_commandline
    conductor_config = AnsibleContainerConductorConfig(list_to_ordereddict(containers_config))
  File "/_ansible/container/__init__.py", line 19, in __wrapped__
    return fn(*args, **kwargs)
  File "/_ansible/container/config.py", line 297, in __init__
    self._process_services()
  File "/_ansible/container/config.py", line 357, 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 275, 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 264, 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 210, 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 244, 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 'flask' was not found in ./roles:/src/roles:/etc/ansible/roles:.
Conductor terminated. Cleaning up.      command_rc=1 conductor_id=ebddaca72c02d2f0eb20d37e85511d869fcc29175e947726d949286348dc4a3b save
_container=False
Parsing conductor CLI args.
- downloading role 'solr', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-solr/archive/4.2.2.tar.gz
- extracting geerlingguy.solr to /tmp/tmplHyWDz/geerlingguy.solr
ERROR   Failed to load container.yml: [Errno 2] No such file or directory: '/src/container.yml'
Undoing changes to .yml files
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__
- geerlingguy.solr (4.2.2) was installed successfully
    return fn(*args, **kwargs)
  File "/_ansible/container/cli.py", line 399, in conductor_commandline
    **params)
  File "/_ansible/container/__init__.py", line 19, in __wrapped__
    return fn(*args, **kwargs)
  File "/_ansible/container/core.py", line 940, in conductorcmd_install
    galaxy.install(roles)
  File "/_ansible/container/utils/galaxy.py", line 74, in install
    self._update_container_yml(role_obj)
  File "/_ansible/container/utils/galaxy.py", line 135, in _update_container_yml
    raise exceptions.AnsibleContainerGalaxyFatalException('Failed to load container.yml: %s' % str(exc))
container.exceptions.AnsibleContainerGalaxyFatalException: Failed to load container.yml: [Errno 2] No such file or directory: '/src/con
tainer.yml'
Conductor terminated. Cleaning up.      command_rc=1 conductor_id=493a4cb91702e61cb9a03f5f1e283754768e0fc6b94cdf0d689a68ea55cd210c save
_container=False
ERROR   Conductor exited with status 1
Voronenko commented 5 years ago

If it still actual, I suggest to prepare small repo with use case with instructions in Readme, and put it on github