Giter VIP home page Giter VIP logo

ansible-container's Introduction

Deprecated

The ansible-container project is now officially deprecated. We will no longer be maintaining this repo or accepting any issues or pull requests.

The ansible-container project did two things, broadly speaking: it built containers, and it deployed containers to Kubernetes. Now there are new successor projects that perform these tasks.

For people who have been using ansible-container to build containers, we recommend using the ansible-bender project: https://github.com/ansible-community/ansible-bender

For people who have been using ansible-container to deploy containers to Kubernetes, we recommend using Ansible Operators:

https://learn.openshift.com/ansibleop/ansible-operator-overview/

Thanks to all those who have used and contributed to ansible-container.

Original README below

Ansible Container

Ansible Container is a tool for building Docker images and orchestrating containers using Ansible playbooks.

How it works

Use Ansible Container to manage the container lifecycle from development, through testing, to production:

  • ansible-container init

    Creates files in the current directory to get you started. Read the comments, and edit to suit your needs.

  • ansible-container install

    Downloads Ansible-Container-ready roles from Ansible Galaxy, and installs them in your project.

  • ansible-container build

    Creates images from your Ansible playbooks.

  • ansible-container run

    Launches the containers specified in the orchestration document, container.yml, for testing the built images. The format of container.yml is nearly identical to Docker Compose.

  • ansible-container deploy

    Pushes the project's container images to a registry of your choice, and generates a playbook capable of deploying the project on a supported cloud provider.

Installing

Install using pip, the Python package manager:

$ sudo pip install "ansible-container[docker,openshift]"

Or, to install without root privileges, use virtualenv to first create a Python sandbox:

$ virtualenv ansible-container
$ source ansible-container/bin/activate
$ pip install "ansible-container[docker,openshift]"

For more details, prerequisite, and instructions on installing the latest development release, please view our Installation Guide.

Getting started

For examples and a quick tour of Ansible Container visit Getting Started at our docs site.

Visit the Ansible Container Demo for a complete walk-through of managing an application from development through cloud deployment.

Get Involved

Branch Information

  • The develop branch is the release actively under development.
  • The master branch corresponds to the latest stable release available at PyPi.
  • Submit pull requests for bug fixes and new features to develop.
  • View the roadmap for a list of features currently under development.
  • Contributors welcome! Get started by reviewing CONTRIBUTORS.md.

Authors

View AUTHORS for a list contributors to Ansible Container. Thanks everyone!

Ansible Container is an Ansible by Red Hat sponsored project.

ansible-container's People

Contributors

concaf avatar ddelbondio avatar dustymabe avatar ehelms avatar evgeni avatar gbraad avatar geerlingguy avatar gerl1ng avatar gnosek avatar gregdek avatar gundalow avatar josiahg avatar lukeshortcloud avatar marc-sensenich avatar marcosdiez avatar marcusianlevine avatar mattclay avatar mcarden avatar mhumesf avatar nonotest avatar pilou- avatar procrypt avatar roderickrandolph avatar ryansb avatar sidharthsurana avatar splisson avatar tomastomecek avatar voronenko avatar wbrefvem avatar xenlo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-container's Issues

Python error

Error when trying to run the following command.

[root@earth ansible-container] # ansible-container init
Traceback (most recent call last):
File "/usr/bin/ansible-container", line 9, in
load_entry_point('ansible-container==0.1', 'console_scripts', 'ansible-container')()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2355, in load
return self.resolve()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2361, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/cli.py", line 13, in
from . import engine
File "/usr/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/engine.py", line 17, in
from compose.config.config import load as config_load, find as config_find
ImportError: No module named compose.config.config

Replacing Dockerfile convenience directives

There are directives in the Dockerfile syntax that provide needed shortcuts for doing things like creating environment vars, setting the working directory, etc. These are examples I've thought of or run into thus far:

  • env
  • workdir
  • entrypoint

These are really documentation issues and not a deficiency in ansible-container. For example, both env and entrypoint can be specified in the compose used to instantiate the services/containers at run time. So we might not have a way (I don't think) to bake these settings into the image, but we can certainly inject them at run time.

The workaround for workdir is most likely to just include the starting directory in the command to be executed. And that perhaps brings up another point- the command won't be baked into the image, but specified at run time.

Docker beta support?

Hi,

The project is dependent on Docker Toolbox library (docker-compose) and therefore wouldn't benefit from the new xhyve VM.

Do you have any ideas how this would be possible?

Cheers,

support running on local docker daemon (via docker socket)

Currently it is a requirement that a user have the Docker daemon listening via tcp or (recommended) via tls. For users running natively on linux and targeting the docker daemon on the local host there is no reason to use DOCKER_HOST or to expose their local docker daemon via tcp. It would be nice if we supported this as a use case.

I understand that ansible spins up a container that then communicates with the docker daemon from inside the container and that using DOCKER_HOST simplifies this design model. However, it is pretty simple to mount the docker socket into that container and achieve the same functionality.

Ansible Options Failure

Hi,

According to the documentation, I should be able to pass in additional parameters to ansible during creation, i.e.,

usage: ansible-container build [-h] [--flatten] [--no-purge-last]
                               [--from-scratch]
                               [ansible_options [ansible_options ...]]

positional arguments:
  ansible_options  Provide additional commandline arguments to Ansible in
                   executing your playbook. If you use this argument, you will
                   need to use -- to prefix your extra options. Use this
                   feature with caution.

Yet, when I try to do this:

ansible-container --debug build --from-scratch -- -e artifact=foo.jar

I'm receiving this error:

Cleaning up Ansible Container builder...
--list-hosts
ansible-container_1  | ERROR! the playbook: [-e, could not be found
ansible_ansible-container_1 exited with code 1

This is the command that Ansible is running:

command: "/usr/local/bin/ansible-playbook -vvv -i /etc/ansible/inventory/hosts -c docker ['-e', 'artifact=foo.jar'] main.yml"

Perhaps I've read the documentation incorrectly?

-=david=-

setup.py install - error: Could not find suitable distribution for Requirement.parse('functools32==3.2.3.post2')

So not sure if this is an error with ansible-container per-se, or something specific to functools, however after running setup, I see the below error.

Installing ansible-container script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg
Processing dependencies for ansible-container==0.1
Searching for functools32==3.2.3.post2
Reading https://pypi.python.org/simple/functools32/
No local packages or download links found for functools32==3.2.3.post2
error: Could not find suitable distribution for Requirement.parse('functools32==3.2.3.post2')

For reference, I also installed functools32 from pip:

$ pip search functools32
functools32               - Backport of the functools module from Python 3.2.3 for use on 2.7 and PyPy.
  INSTALLED: 3.2.3-2 (latest)

What's interesting is that the ansible-container gets installed:

$ dir /usr/local/bin/ansible-container
4.0K -rwxr-xr-x 1 root root 345 Jun 29 13:20 /usr/local/bin/ansible-container

However, it will throw an error when trying to run:

$ /usr/local/bin/ansible-container
Traceback (most recent call last):
  File "/usr/local/bin/ansible-container", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2749, in <module>
    working_set = WorkingSet._build_master()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 446, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 459, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 628, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: functools32==3.2.3.post2

Is this just something where I can modify the setup to look for 3.2.3-2 instead of 3.2.3.post2?

Ansible role not copying files correctly

I have been setting up ansible-container to provision some docker containers. I am trying to provision these containers with a few roles I have defined. In the roles I copy files from a directory above the actual task, this is an example:
copy: src: ../files/elastic-repo dest: /etc/yum.repos.d/elasticsearch.repo

This does not seem to work properly. I am getting this error:
ansible-container_1 | fatal: [mgt]: FAILED! => {"changed": false, "failed": true, "msg": "Unable to find '../files/elastic-repo' in expected paths."} ansible-container_1 |

I have already tested this in a virtual machine so I know the syntax is correct.

Error: image library/example-django not found

I've followed the installation instructions and everything went well. Also building the example image went ok but when I want to run the example containter as described in the README.md I receive this error message.

$ sudo ansible-container run

No DOCKER_HOST environment variable found. Assuming UNIX socket at /var/run/docker.sock The PWD variable is not set. Defaulting to a blank string. Attaching to ansible_ansible-container_1 Cleaning up Ansible Container builder... The PWD variable is not set. Defaulting to a blank string. Pulling repository docker.io/library/example-django Error: image library/example-django not found

I'm very new into this and I'm asking myself, am I doing something wrong or is the image not available any more?

call files "build.yml" and "run.yml"?

Upon reflection, seems perhaps more intuitive to change "container.yml" to "run.yml", since that's the file we reference when running "ansible-container run", and to change "main.yml" to "build.yml", since that's the file we reference when running "ansible-container build".

Since we're throwing some new concepts at users, any assistance we can give them in mapping those concepts is useful.

Support detached run, stop, and restart

Hello.
Is it possible to use something like docker-compose -d or docker run -d image with ansible-container?
I have tried to run a container with nginx with ansible-container, but it exits with exit 0

version: "1" 
services:
  nginx:
    image: centos:7
    ports:
      - "80:80" 
    command: ['/usr/bin/dumb-init', '/usr/sbin/nginx', '-c', '/etc/nginx/nginx.conf' ]
    volumes:
      - /var/www:/usr/share/nginx/html
Attaching to ansible_ansible-container_1
Cleaning up Ansible Container builder...
Attaching to ansible_nginx_1
ansible_nginx_1 exited with code 0

Errors on Fedora 24

I can't seem to get this up and working on F24 (beta right now) - perhaps an install guide might help but for now I was following some of the steps from the Dockerfile in #4. Either way here are the errors I am seeing:

[root@f24 ansible-container (master=)]# git log | head -n 1
commit ebdc723c0e8866472c6aade2c2d313a440a5582a
[root@f24 ansible-container (master=)]# cd test-v1/
[root@f24 test-v1 (master=)]# ansible-container --debug build --no-flatten
Ansible Container image has ID sha256:08b6b60b643bc1be5bc7114d7ed7b684c14eb2c09a6bf6111fb72a17ef28b809
Using temporary directory /tmp/tmpkb98_c...
Starting Compose engine to build your images...
Using temporary directory /tmp/tmpyQnzYZ...
The DOCKER_CERT_PATH variable is not set. Defaulting to a blank string.

ERROR: for ansible-container  create .: volume name invalid: "." includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed
Attaching to 
Cleaning up temporary directory /tmp/tmpyQnzYZ...
The DOCKER_CERT_PATH variable is not set. Defaulting to a blank string.

ERROR: for ansible-container  create .: volume name invalid: "." includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed
Attaching to ansible_host2_1, ansible_host1_1

This then waits forever and I have to CTRL-C:

^CGracefully stopping... (press Ctrl+C again to force)
Stopping ansible_host1_1 ... 
Stopping ansible_host1_1 ... done
Stopping ansible_host2_1 ... done
Cleaning up temporary directory /tmp/tmpkb98_c...
need more than 0 values to unpack
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/cli.py", line 126, in commandline
    **vars(args))
  File "/usr/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/engine.py", line 108, in cmdrun_build
    limit=1, all=True
ValueError: need more than 0 values to unpack

Default to --from-scratch if images aren't in engine

If you run ansible-container build the first time without specifying --from-scratch, it tries to pull images from Docker Hub. It should check the engine to make sure there are images first, and if not, set --from-scratch.

Error: TemplateNotFound: shipit_role/test.j2.yml

I followed the steps for installation and was able to successfully complete an ansible-container build from the examples: https://github.com/ansible/ansible-container-examples

I want to deploy it on a kubernetes cluster and the shipit command throws me an error:

Creating role path /home/centos/ansible-container-examples/django-cms/ansible/roles/django-cms-kubernetes
Rendering template for test/test.j2.yml
shipit_role/test.j2.yml
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/cli.py", line 154, in commandline
getattr(engine, u'cmdrun_{}'.format(args.subcommand))(*_vars(args))
File "/usr/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/engine.py", line 337, in cmdrun_shipit
shipit_engine_obj.run()
File "/usr/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/shipit/kubernetes/engine.py", line 28, in run
self.init_role()
File "/usr/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/shipit/base_engine.py", line 139, in init_role
*_context)
File "/usr/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/utils.py", line 68, in jinja_render_to_temp
j2_tmpl = j2_env.get_template(template_file)
File "/usr/lib64/python2.7/site-packages/jinja2/environment.py", line 812, in get_template
return self._load_template(name, self.make_globals(globals))
File "/usr/lib64/python2.7/site-packages/jinja2/environment.py", line 774, in _load_template
cache_key = self.loader.get_source(self, name)[1]
File "/usr/lib64/python2.7/site-packages/jinja2/loaders.py", line 187, in get_source
raise TemplateNotFound(template)
TemplateNotFound: shipit_role/test.j2.yml

Am I missing something ?

Feature request: build --no-export

Summary: add a command line option to the build command (--no-export) which will make ansible-container NOT export/commit the newly created container.

Reasoning: ansible-container seems a very good candidate to automate not only the creation of container images, but actually also to automate the testing of ansible playbooks and roles. In the case of tests, one usually doesn't want to keep an image.

Any thoughts? Is this thinking correct?

Previous images left around

With my setup, I am seeing errors removing previous images at the end of the build stage which leaves around multiple containers and images that starts to eat a lot of disk space.

Error:

ansible_ansible-container_1 exited with code 0
Aborting on container exit...
Stopping ansible_foreman_1 ... done
Stopping ansible_postgresql_1 ... done
Exporting built containers as images...
Committing image...
Exported containers-foreman with image ID sha256:93739643fd571df6933ce22bfb767659f34b5dc6523e5582c8f69bda39bffa6d
Cleaning up foreman build container...
Removing previous image...
409 Client Error: Conflict ("conflict: unable to delete 79b760a5b4db (cannot be forced) - image has dependent child images")

Python Error

I am running it in my Macbook
Already installed docker toolbox and the docker-machine is running.

Failed with python error.

gopi.sabapathy@holbmac0293 ๎‚ฐ ~/projects/ansible-container ๎‚ฐ ๎‚  master ๎‚ฐ sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", line 11, in <module>
    packages=find_packages(include='container.*'),
TypeError: find_packages() got an unexpected keyword argument 'include'
 โœ˜ gopi.sabapathy@holbmac0293 ๎‚ฐ ~/projects/ansible-container ๎‚ฐ ๎‚  master ๎‚ฐ python --version
Python 2.7.10

If I use python3.5 it ends with different error message: (Tail of the error message)

Downloading https://pypi.python.org/packages/06/f2/ff20f2d2fd4757be329c8ecb81e9e7fa3bec0b65445821e3a575410cf194/py2-ipaddress-3.4.1.tar.gz#md5=47734313c841068e3d5386d048d01c3d
Processing py2-ipaddress-3.4.1.tar.gz
Writing /tmp/easy_install-wspxizt2/py2-ipaddress-3.4.1/setup.cfg
Running py2-ipaddress-3.4.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-wspxizt2/py2-ipaddress-3.4.1/egg-dist-tmp-6r6cm835
error: Setup script exited with py2-ipaddress: For Python 3.x, please use the official ipaddress module.

Init Fails w/ ansible-container build due to Debian Jessie Fetch Package Directory

SUMMARY

Trying to start a project that uses Debian Jessie, but ansible-container build fails.

In case these were important:

container.yml

version: '1'
services:
  express:
    image: node:argon
    command: [ "echo", "hello" ]

registries: {}

main.yml

- hosts: express
  tasks:
    - name: Make AppDir
      file: name=/usr/src/app state=directory recurse=true

ACTUAL RESULT

Full Debug Gist: https://gist.github.com/darkn3rd/792ef1356058667ddf91e63c13d7c047

...
...
{"stream":"\u001b[91mFailed to fetch http://httpredir.debian.org/debian/dists/jessie/main/binary-amd64/Packages  404  Not Found [IP: 128.31.0.66 80]\n\n\u001b[0m"}

{"stream":"\u001b[91mE: \u001b[0m"}

{"stream":"\u001b[91mSome index files failed to download. They have been ignored, or old ones used instead.\n\u001b[0m"}

{"errorDetail":{"code":100,"message":"The command '/bin/sh -c apt-get update -y \u0026\u0026     apt-get install -y apt-transport-https ca-certificates \u0026\u0026     echo \"deb https://apt.dockerproject.org/repo debian-jessie main\"\u003e/etc/apt/sources.list.d/docker.list \u0026\u0026     apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D \u0026\u0026     apt-get update -y \u0026\u0026     apt-get install -y python-setuptools git python-pip docker-engine \u0026\u0026     apt-get clean \u0026\u0026 rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*' returned a non-zero code: 100"},"error":"The command '/bin/sh -c apt-get update -y \u0026\u0026     apt-get install -y apt-transport-https ca-certificates \u0026\u0026     echo \"deb https://apt.dockerproject.org/repo debian-jessie main\"\u003e/etc/apt/sources.list.d/docker.list \u0026\u0026     apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D \u0026\u0026     apt-get update -y \u0026\u0026     apt-get install -y python-setuptools git python-pip docker-engine \u0026\u0026     apt-get clean \u0026\u0026 rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*' returned a non-zero code: 100"}

No image with the name ansible-container-builder
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/cli.py", line 154, in commandline
    getattr(engine, u'cmdrun_{}'.format(args.subcommand))(**vars(args))
  File "/usr/local/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/engine.py", line 248, in cmdrun_build
    create_build_container(engine_obj, base_path)
  File "/usr/local/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/engine.py", line 352, in create_build_container
    builder_img_id = container_engine_obj.get_builder_image_id()
  File "/usr/local/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/docker/engine.py", line 174, in get_builder_image_id
    return self.get_image_id_by_tag(self.builder_container_img_tag)
  File "/usr/local/lib/python2.7/site-packages/ansible_container-0.1-py2.7.egg/container/docker/engine.py", line 127, in get_image_id_by_tag
    raise NameError('No image with the name %s' % name)
NameError: No image with the name ansible-container-builder

Looked through the debug output to see what is wrong with the side-kick container build, found that the URL tries to access a non-existent Package directory. There were files in the parent directory like Package.gz.

System Configuration

  • Host OS: El Capitan
  • Docker: Docker version 1.11.2, build b9f10c9
  • Docker-Compose: docker-compose version 1.7.0, build 0d7bf73
  • Python: Python 2.7.11

Is it possible to set a custom tag format?

Is it possible to set a custom tag format?

I would like to use ansible-compose as part of our build process. Ideally, it would tag each image with our own version convention.

Project plan / pip release

Awesome project, addressing a significant pain for ansible and docker users!
I really want to try it out, but the separate build process is a hurdle. Any plans to merge it into Ansible, so that non-Python developers can give it a try?

Thanks

Be able to use ansible-container build without an /ansible folder

I'd like to either specify the folder to build (ex. ansible-container build -f ./test or even ansible-container build test/ansible).

Another thing is that I'm forced to use a folder named ansible. ansible-container should detect whether there is a container.yml in the folder and run it appropriately without the need of having an ansible container.

LXD support ?

Hi !

I just <3 this project because it opens a wide range of new possibilities. I can see how this is awesome for testing before deploying on docker-based PaaS like OpenShift 3 or even plain kubernetes !

However, docker doesn't cut it to test deployment on OpenStack VMs because it's an application containerization system, while full system containers provide more value for testing deployment on OpenStack full-system VMs.

For example, start-stop-daemon won't work on docker without ptrace capabilities, so we couldn't even test a pgbouncer role properly on docker at first. Let alone testing complete infrastructure deployment testing :)

Have you considered adding LXD support ?

What's your opinion on it ?

Would you be open for discussion and patch review for that ?

Thanks !

Build performance

I've been banging my way through creating an Ansible playbook that will build an image similar to Docker's Django demo: https://docs.docker.com/compose/django/.

It's been an iterative, trial-and-error process, which is pretty typical when you're developing a playbook from scratch. Write a few tasks. Run. Debug errors. Run. Debug errors. Repeat.

Each time I run ansible-container build I have to wait quite awhile before my playbook begins executing and building the container for my eventual image. From what I can see, it seems to be building a new Ansible container every time.

Is there any way to make this faster? Does it really need to build the Ansible container each time? Seems like all it really needs is an updated copy of the ansible directory, which might be solved using a host volume. We could also start with a base image that includes Ansible already installed.

Reference for Container.yml

Are there any documentation reference for the tokens that can be used in the container reference? I'm not sure how to convert my Dockerfile into a container.yml. The current reference documentation just documents that commands. Using the example as my go-to reference for now.

Docker Mac Beta (native) is incompatible

Attaching to ansible_ansible-container_1, ansible_account_1
ansible-container_1  |
ansible-container_1  | PLAY [account] *****************************************************************
ansible-container_1  |
ansible-container_1  | TASK [setup] *******************************************************************
ansible-container_1  | Cannot connect to the Docker daemon. Is the docker daemon running on this host?
ansible-container_1  | An exception occurred during task execution. To see the full traceback, use -vvv. The error was: CalledProcessError: Command '['/usr/bin/docker', 'version']' returned non-zero exit status 1
ansible-container_1  | fatal: [account]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
ansible-container_1  |
ansible-container_1  | NO MORE HOSTS LEFT *************************************************************
ansible-container_1  |  to retry, use: --limit @main.retry
ansible-container_1  |
ansible-container_1  | PLAY RECAP *********************************************************************
ansible-container_1  | account                    : ok=0    changed=0    unreachable=0    failed=1
ansible-container_1  |
ansible_ansible-container_1 exited with code 1

HTTP timeout

Noticed when running the build command that long running tasks cause a timeout. I think the timeout is a parameter that needs to be set when the docker-py client is instantiated, but I could be wrong.

An example is running *yum: name= {{ item }}" and iterating over a list of package names. If the time it takes to install all of the packages exceeds some threshold, a timeout occurs.

How to run multiple instances of the same service/container?

Hi,

I'd like to know whether (and how) it's possible to build a service and run multiple instances of this service? This probably relates to being able to group the services together as with regular inventory groups and provide functionality like docker-compose scale=...

Any ideas?

thx, Koen

ansible-container can incorrectly assume names of container images

ansible-container assumes that the name of the image relating to a container to be brought up is compose-<name>. If you have a playbook that doesn't require a "build" for certain images then there will be no new committed image in the form of compose-<name> build on the machine.

This means that running ansible-container run will error because of the bad assumption.

500 Internal Server Error when *.retry file exists

Seeing the following error:

$ ansible-container --debug build
(Re)building the Ansible Container image is necessary.
Using temporary directory /var/folders/g_/mr68c1yn1rl4b7qh6pntbmmm0000gn/T/tmpo1uinU...
Building Docker Engine context...
Starting Docker build of Ansible Container image...
Cleaning up temporary directory /var/folders/g_/mr68c1yn1rl4b7qh6pntbmmm0000gn/T/tmpo1uinU...
500 Server Error: Internal Server Error ("Untar re-exec error: exit status 1: output: unexpected EOF")
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/ansible_container-0.1-py2.7.egg/container/cli.py", line 144, in commandline
    **vars(args))
  File "/Library/Python/2.7/site-packages/ansible_container-0.1-py2.7.egg/container/engine.py", line 92, in cmdrun_build
    build_output = build_buildcontainer_image(base_path)
  File "/Library/Python/2.7/site-packages/ansible_container-0.1-py2.7.egg/container/engine.py", line 81, in build_buildcontainer_image
    tag='ansible-container-builder')]
  File "/Library/Python/2.7/site-packages/docker/client.py", line 238, in _stream_helper
    yield self._result(response)
  File "/Library/Python/2.7/site-packages/docker/client.py", line 158, in _result
    self._raise_for_status(response)
  File "/Library/Python/2.7/site-packages/docker/client.py", line 154, in _raise_for_status
    raise errors.APIError(e, response, explanation=explanation)
APIError: 500 Server Error: Internal Server Error ("Untar re-exec error: exit status 1: output: unexpected EOF")

Steps to reproduce:

  1. ansible-container --debug build
  2. main.yml playbook errors and leaves main.retry in the ansible directory
  3. ansible-container --debug build

Removing main.retry from the ansible directory fixes the issue. Perhaps the build command should remove any *.retry files before attempting to start the build?

Build trackback due to image child-parent creation order

SUMMARY

Getting a lot of these unable to delete $sha (cannot be forced) - image has dependent child images") messages when making and change and wanting to rebulid.

STEPS

  1. ansible-container build
  2. change something in main.yml, such as mkdir task
  3. ansible-container build

ACTUAL RESULT

(Re)building the Ansible Container image.
Building Docker Engine context...
Starting Docker build of Ansible Container image (please be patient)...
Ansible Container image has ID sha256:8b59430249e8ed9e5e275c8b35fc9eb53500f61250d4e0bdbad71ff3eba2be34
Starting Docker Compose engine to build your images...
Attaching to ansible_ansible-container_1
Cleaning up Ansible Container builder...
Attaching to ansible_express_1, ansible_ansible-container_1
ansible-container_1  | 
ansible-container_1  | PLAY [express] *****************************************************************
ansible-container_1  | 
ansible-container_1  | TASK [setup] *******************************************************************
ansible-container_1  | ok: [express]
ansible-container_1  | 
ansible-container_1  | TASK [Make AppDir] *************************************************************
ansible-container_1  | changed: [express]
ansible-container_1  | 
ansible-container_1  | PLAY RECAP *********************************************************************
ansible-container_1  | express                    : ok=2    changed=1    unreachable=0    failed=0   
ansible-container_1  | 
ansible_ansible-container_1 exited with code 0
Aborting on container exit...
Stopping ansible_express_1 ... done
Exporting built containers as images...
Committing image...
Exported express-express with image ID sha256:af73a679fb777d1c07a6820562879b4dc3765c872d9eed10edc513f0ac6924a4
Cleaning up express build container...
Removing previous image...
409 Client Error: Conflict ("conflict: unable to delete 8bc3842ac7ad (cannot be forced) - image has dependent child images")

EXPECTED RESULT

That it would build and apply the change.

SCRIPTS

version: '1'
services:
  express:
    image: node:argon
registries: {}
- hosts: express
  tasks:
     - name: Make AppDir
       file: name=/usr/src/app state=directory recurse=true

NOTES

I have to go force purge my image before rebuilding. This seems to work.

docker images | grep express | awk '{print $3}' | xargs docker rmi โ€”force

ansible-container build fails with geerlingguy.apache role with /usr/bin/python: ont found

I'm working on a fork of ansible-container-examples to see if I can get a drupal site working.

I'm going to work with geerlingguy's roles, I added a playbook that just included geerlingguy.apache or geerlingguy.drupal, installed the roles manully, then on ansible-container build I get

"/bin/sh: 1: /usr/bin/python: not found\n"

container.yml:

version: "1"
services:
  drupal:
    image: ubuntu:14.04

  database:
    image: mariadb
    environment:
      MYSQL_ROOT_PASSWORD: 'RANDOMSECUREPASSWORD12345'
      MYSQL_DATABASE: 'drupal'
      MYSQL_USER: 'drupal'
      MYSQL_PASSWORD: 'password'

registries: {}

main.yml:

# This should be your Ansible playbooks to provision your containers.
# An inventory will be automatically created using the names of the services
# from your container.yml file.
# Add any roles or other modules you'll need to this directory too.
# For many examples of roles, check out Ansible Galaxy: https://galaxy.ansible.com/


- hosts: drupal
  roles:
    - { role: geerlingguy.drupal }

I'm going to try and add python to the base image.

Issue with building

โ–ถ cat container.yml 
version: "1"
services:
  web:
   image: nginx
   ports:
     - "80:80"
 - hosts: all
   gather_facts: false
   tasks:
     - raw: which python || apt-get update
     - raw: (which python && which aptitude) || apt-get install -y python python-apt aptitude
 - hosts: web
   tasks:
     - name: Upgrade APT
       apt: upgrade=yes
     - name: Install ca-certificates
       apt: name=ca-certificates state=latest
     - name: Install dumb-init
       apt: deb=https://github.com/Yelp/dumb-init/releases/download/v1.0.2/dumb-init_1.0.2_amd64.deb
     - name: Install Apache
       apt: name=apache2 state=latest

Error:

โ–ถ ansible-container build
(Re)building the Ansible Container image.
Building Docker Engine context...
Starting Docker build of Ansible Container image...
Ansible Container image has ID sha256:f8be78751e9326d50a94cf7d9a2195655baa9d45a9844bb62f1eabcb4611fca1
Starting Docker Compose engine to build your images...
Attaching to ansible_ansible-container_1
Cleaning up Ansible Container builder...
Attaching to ansible_ansible-container_1, ansible_web_1
ansible-container_1  | 
ansible-container_1  | PLAY [all] *********************************************************************
ansible-container_1  | 
ansible-container_1  | TASK [raw] *********************************************************************
ansible-container_1  | Cannot connect to the Docker daemon. Is the docker daemon running on this host?
ansible-container_1  | An exception occurred during task execution. To see the full traceback, use -vvv. The error was: CalledProcessError: Command '['/usr/bin/docker', 'version']' returned non-zero exit status 1
ansible-container_1  | fatal: [web]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
ansible-container_1  | 
ansible-container_1  | NO MORE HOSTS LEFT *************************************************************
ansible-container_1  |  [WARNING]: Could not create retry file 'main.retry'.         Unable to create
ansible-container_1  | local directories(): [Errno 2] No such file or directory: ''
ansible-container_1  | 
ansible-container_1  | PLAY RECAP *********************************************************************
ansible-container_1  | web                        : ok=0    changed=0    unreachable=0    failed=1   
ansible-container_1  | 
ansible_ansible-container_1 exited with code 1
Aborting on container exit...
Stopping ansible_web_1 ... done
Ansible playbook run failed.
Cleaning up Ansible Container builder...

Docker version:

~/test/ansible                                                                                                                                                                                                                                                
โ–ถ docker version
Client:
 Version:      1.11.2
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   b9f10c9
 Built:        Wed Jun  1 21:20:08 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.11.2
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   b9f10c9
 Built:        Wed Jun  1 21:20:08 2016
 OS/Arch:      linux/amd64

"NameError: No container with the name ansible-container" in example

I noticed you guys got rid of the requirement to have the ansible-container definition in the compose file, but for some reason it looks like when going to run the ansible scripts, it has trouble finding the orchestration container. ansible-container gets built properly, and templated out properly. But then this occurs:

No container with the name ansible-container
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/cli.py", line 178, in commandline
    **vars(args))
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/engine.py", line 244, in cmdrun_build
    touched_hosts = engine_obj.hosts_touched_by_playbook()
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/docker/engine.py", line 56, in hosts_touched_by_playbook
    builder_container_id = self.get_builder_container_id()
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/docker/engine.py", line 172, in get_builder_container_id
    return self.get_container_id_by_name(self.builder_container_img_name)
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/docker/engine.py", line 132, in get_container_id_by_name
    raise NameError('No container with the name %s' % name)
NameError: No container with the name ansible-container

Adding the container back to the containers.yml file helps, but then I run into a hang issue (will deal with that separately):

  ansible-container:
    image: python:2.7

Full trace below:

$ sudo ansible-container --debug build
Project name is example
Initialized with params: {'purge_last': True, 'subcommand': 'build', 'engine_args': {'engine_name': 'docker', 'purge_last': True, 'subcommand': 'build', 'engine_args': {...}, 'base_path': '/home/ubuntu/ansible-container/example', 'ansible_options': u'', 'flatten': True, 'kwargs': {'debug': True, 'subcommand': 'build', 'no_purge_last': True}, 'debug': True, 'rebuild': False, 'no_purge_last': True}, 'no_purge_last': True, 'ansible_options': u'', 'flatten': True, 'kwargs': {'debug': True, 'subcommand': 'build', 'no_purge_last': True}, 'debug': True, 'rebuild': False}
(Re)building the Ansible Container image.
Using temporary directory /tmp/tmpPzeAbA...
Building Docker Engine context...
Rendered Jinja Template:
FROM python:2.7

# Add the dockerproject repo
RUN apt-get update -y
RUN apt-get install -y apt-transport-https ca-certificates
RUN echo "deb https://apt.dockerproject.org/repo debian-jessie main">/etc/apt/sources.list.d/docker.list
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

# Install required packages, including docker-engine which gives us access a docker client
RUN apt-get update -y && \
    apt-get install -y python-setuptools git python-pip docker-engine && \
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ADD hosts  /etc/ansible/inventory/hosts
ADD ansible /ansible-tmp/
# RUN pip install -q --no-cache-dir 'ansible=='
RUN pip install -q --no-cache-dir -e git+https://github.com/ansible/ansible.git@devel#egg=ansible
RUN test '(! -f /ansible-tmp/requirements.txt)' || pip install --no-cache-dir -r /ansible-tmp/requirements.txt
RUN rm -rf /ansible-tmp/
Rendered Jinja Template:
[docker]
gulp ansible_host=ansible_gulp_1
static ansible_host=ansible_static_1
postgresql ansible_host=ansible_postgresql_1
django ansible_host=ansible_django_1

Starting Docker build of Ansible Container image...
Cleaning up temporary directory /tmp/tmpPzeAbA...
{"stream":"Step 1 : FROM python:2.7\n"}

{"status":"Pulling from library/python","id":"2.7"}

{"status":"Digest: sha256:53ececa6c98c67079fc019644b364608f7fa4ae06cff372a5cb2fc82c90961d4"}

{"status":"Status: Image is up to date for python:2.7"}

{"stream":" ---\u003e a047e3d0ae2b\n"}

{"stream":"Step 2 : RUN apt-get update -y\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e 668ba94034ca\n"}

{"stream":"Step 3 : RUN apt-get install -y apt-transport-https ca-certificates\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e 3ac2349a75d5\n"}

{"stream":"Step 4 : RUN echo \"deb https://apt.dockerproject.org/repo debian-jessie main\"\u003e/etc/apt/sources.list.d/docker.list\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e a018778e0717\n"}

{"stream":"Step 5 : RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e 71707cb1f3db\n"}

{"stream":"Step 6 : RUN apt-get update -y \u0026\u0026     apt-get install -y python-setuptools git python-pip docker-engine \u0026\u0026     apt-get clean \u0026\u0026 rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e 8a31d2e0fad4\n"}

{"stream":"Step 7 : ADD hosts /etc/ansible/inventory/hosts\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e eb6488041be3\n"}

{"stream":"Step 8 : ADD ansible /ansible-tmp/\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e 2b3220a6a157\n"}

{"stream":"Step 9 : RUN pip install -q --no-cache-dir -e git+https://github.com/ansible/ansible.git@devel#egg=ansible\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e 1ef4452829a3\n"}

{"stream":"Step 10 : RUN test '(! -f /ansible-tmp/requirements.txt)' || pip install --no-cache-dir -r /ansible-tmp/requirements.txt\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e b2177d3d2a2b\n"}

{"stream":"Step 11 : RUN rm -rf /ansible-tmp/\n"}

{"stream":" ---\u003e Using cache\n"}

{"stream":" ---\u003e 4e8f6481e17d\n"}

{"stream":"Successfully built 4e8f6481e17d\n"}

Ansible Container image has ID sha256:4e8f6481e17d352c13054fd0a7547c48f9e99a837cf6b4746411e7ba9e287f45
Using temporary directory /tmp/tmp8onRD2...
Starting Docker Compose engine to build your images...
Using temporary directory /tmp/tmpjOZgym...
Compose derived from config:
{'gulp': {'image': 'centos:7', 'links': ['django'], 'command': '/bin/false', 'user': 'node'}, 'postgresql': {'image': 'centos:7', 'command': ['/usr/bin/dumb-init', 'postgres', '-h', '0.0.0.0', '-D', '/var/lib/pgsql/data'], 'ports': ['5432'], 'volumes': ['/var/lib/pgsql'], 'user': 'postgres'}, 'static': {'command': ['/usr/bin/dumb-init', 'nginx', '-c', '/etc/nginx/nginx.conf'], 'links': ['django'], 'image': 'centos:7', 'ports': ['80:8080'], 'user': 'nginx'}, 'django': {'working_dir': '/django', 'command': ['/usr/bin/dumb-init', '/venv/bin/gunicorn', '-w', '2', '-b', '0.0.0.0:8080', 'example.wsgi:application'], 'links': ['postgresql'], 'image': 'centos:7', 'ports': ['8080'], 'user': 'django'}}
{'gulp': {'command': 'sh -c "while true; do sleep 1; done"', 'user': 'node', 'links': ['django'], 'image': 'centos:7'}, 'postgresql': {'command': 'sh -c "while true; do sleep 1; done"', 'user': 'postgres', 'volumes': ['/var/lib/pgsql'], 'image': 'centos:7', 'ports': ['5432']}, 'static': {'command': 'sh -c "while true; do sleep 1; done"', 'links': ['django'], 'image': 'centos:7', 'ports': ['80:8080'], 'user': 'nginx'}, 'django': {'working_dir': '/django', 'command': 'sh -c "while true; do sleep 1; done"', 'links': ['postgresql'], 'image': 'centos:7', 'ports': ['8080'], 'user': 'django'}}
Config YAML is
django:
  command: sh -c "while true; do sleep 1; done"
  image: centos:7
  links: [postgresql]
  ports: ['8080']
  user: django
  working_dir: /django
gulp:
  command: sh -c "while true; do sleep 1; done"
  image: centos:7
  links: [django]
  user: node
postgresql:
  command: sh -c "while true; do sleep 1; done"
  image: centos:7
  ports: ['5432']
  user: postgres
  volumes: [/var/lib/pgsql]
static:
  command: sh -c "while true; do sleep 1; done"
  image: centos:7
  links: [django]
  ports: ['80:8080']
  user: nginx

Rendered Jinja Template:
ansible-container:
  image: "sha256:4e8f6481e17d352c13054fd0a7547c48f9e99a837cf6b4746411e7ba9e287f45"
  command: ansible-playbook -i /etc/ansible/inventory/hosts -c docker  --list-hosts main.yml
  environment:
    - DOCKER_HOST
    - DOCKER_TLS_VERIFY
    - DOCKER_CERT_PATH=/docker-certs/
    - COMPOSE_HTTP_TIMEOUT=3000
  volumes:
    - $DOCKER_CERT_PATH:/docker-certs/
    - /home/ubuntu/ansible-container/example:/ansible-container/
  working_dir: /ansible-container/ansible/
  stdin_open: true
  tty: true
django:
  command: sh -c "while true; do sleep 1; done"
  image: centos:7
  links: [postgresql]
  ports: ['8080']
  user: django
  working_dir: /django
gulp:
  command: sh -c "while true; do sleep 1; done"
  image: centos:7
  links: [django]
  user: node
postgresql:
  command: sh -c "while true; do sleep 1; done"
  image: centos:7
  ports: ['5432']
  user: postgres
  volumes: [/var/lib/pgsql]
static:
  command: sh -c "while true; do sleep 1; done"
  image: centos:7
  links: [django]
  ports: ['80:8080']
  user: nginx

The DOCKER_CERT_PATH variable is not set. Defaulting to a blank string.

ERROR: for ansible-container  create .: volume name invalid: "." includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed
Attaching to
Cleaning up Ansible Container builder...
Cleaning up temporary directory /tmp/tmpjOZgym...
Cleaning up temporary directory /tmp/tmp8onRD2...
No container with the name ansible-container
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/cli.py", line 178, in commandline
    **vars(args))
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/engine.py", line 244, in cmdrun_build
    touched_hosts = engine_obj.hosts_touched_by_playbook()
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/docker/engine.py", line 56, in hosts_touched_by_playbook
    builder_container_id = self.get_builder_container_id()
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/docker/engine.py", line 172, in get_builder_container_id
    return self.get_container_id_by_name(self.builder_container_img_name)
  File "/usr/local/lib/python2.7/dist-packages/ansible_container-0.1-py2.7.egg/container/docker/engine.py", line 132, in get_container_id_by_name
    raise NameError('No container with the name %s' % name)
NameError: No container with the name ansible-container

Can main.yaml be optional?

Sometimes I'd like to build it without using the main.yaml file, either to use Ansible to deploy the containers with just a straight-up plain-jane nginx Docker container.

Could this be optional (warn the user?)

Changing `main.yml` when using `ansible-container init`

In order to test / use ansible-container as quick as possible. Within ansible-container init files, we should have a basic playbook that echo's foo, or does something simple in nature.

Related to PR #62

For example, this is how it looks like right now when doing ansible-container init:

# This should be your Ansible playbooks to provision your containers.                                                                                                                                                                                          
# An inventory will be automatically created using the names of the services                                                                                                                                                                                   
# from your container.yml file.                                                                                                                                                                                                                                
# Add any roles or other modules you'll need to this directory too.                                                                                                                                                                                            
# For many examples of roles, check out Ansible Galaxy: https://galaxy.ansible.com/                                                                                                                                                                            
#                                                                                                                                                                                                                                                              
# - hosts: all                                                                                                                                                                                                                                                 
#   gather_facts: false                                                                                                                                                                                                                                        
#   tasks:                                                                                                                                                                                                                                                     
#     - raw: which python || apt-get update                                                                                                                                                                                                                    
#     - raw: (which python && which aptitude) || apt-get install -y python python-apt aptitude                                                                                                                                                                 
# - hosts: web                                                                                                                                                                                                                                                 
#   tasks:                                                                                                                                                                                                                                                     
#     - name: Upgrade APT                                                                                                                                                                                                                                      
#       apt: upgrade=yes                                                                                                                                                                                                                                       
#     - name: Install ca-certificates                                                                                                                                                                                                                          
#       apt: name=ca-certificates state=latest                                                                                                                                                                                                                 
#     - name: Install dumb-init                                                                                                                                                                                                                                
#       apt: deb=https://github.com/Yelp/dumb-init/releases/download/v1.0.2/dumb-init_1.0.2_amd64.deb                                                                                                                                                          
#     - name: Install Apache                                                                                                                                                                                                                                   
#       apt: name=apache2 state=latest 

We should be using Version 2 of Docker Compose

Version 1 of Docker Compose will be deprecated in the near future[1]. Version 1 also does not support named volumes, networks or build arguments[1].

(IMO) Most of the community has already switched to Version 2 so we should be using that in our examples and builds.

  1. https://docs.docker.com/compose/compose-file/#version-1
Version 1 is supported by Compose up to 1.6.x. It will be deprecated in a future Compose release.

Version 1 files cannot declare named volumes, networks or build arguments.

shipit fails with selinux enabled

Running on Fedora 24 I get a failure when running ansible-container shipit. Without selinux enable this works fine. This is most likely because we are mounting directories into a container (the ansible-container) and trying to modify the contents.

[root@f24 test]# pwd
/sharedfolder/ansible-container/test
[root@f24 test]# git remote -v
origin  https://github.com/ansible/ansible-container (fetch)
origin  https://github.com/ansible/ansible-container (push)
[root@f24 test]# ls
ansible
[root@f24 test]# rpm -q docker
docker-1.10.3-9.git667d6d1.fc24.x86_64
[root@f24 test]#
[root@f24 test]# setenforce 1
[root@f24 test]# ansible-container --debug shipit
Project name is test
Initialized with params: {'shipit_engine': 'openshift', 'subcommand': 'shipit', 'save_config': False, 'engine_args': {'shipit_engine': 'openshift', 'engine_name': 'docker', 'subcommand': 'shipit', 'save_config': False, 'engine_args': {...}, 'base_path': '/sharedfolder/ansible-container/test', 'kwargs': {'debug': True, 'subcommand': 'shipit', 'shipit_engine': 'openshift', 'save_config': False}, 'debug': True}, 'kwargs': {'debug': True, 'subcommand': 'shipit', 'shipit_engine': 'openshift', 'save_config': False}, 'debug': True}
Creating roles path /sharedfolder/ansible-container/test/roles
Using temporary directory /tmp/tmpf4u9Cz...
Executing ansible-galaxy init test
Compose derived from config:
{'host2': {'image': 'ubuntu:trusty', 'command': ['/usr/bin/dumb-init', '/usr/sbin/apache2ctl', '-D', 'FOREGROUND'], 'ports': ['80:80']}, 'host1': {'image': 'ubuntu:trusty', 'command': '/bin/false'}}
{'host2': {'image': 'ubuntu:trusty', 'command': 'echo "Started"', 'ports': ['80:80']}, 'host1': {'image': 'ubuntu:trusty', 'command': 'echo "Started"'}}
Config YAML is
host1: {command: echo "Started", image: 'ubuntu:trusty'}
host2:
  command: echo "Started"
  image: ubuntu:trusty
  ports: ['80:80']

Rendered Jinja Template:
# Execute ansible-galaxy init to create the shipit role
ansible-container:
  image: "sha256:05abeabd1f189f0e921448a7bf914d6ca1ee8bd8ec4b25bd32c1c2e179280e18"
  command: ansible-galaxy init -p /roles --force test
  volumes:
      - /sharedfolder/ansible-container/test/roles:/roles
host1: {command: echo "Started", image: 'ubuntu:trusty'}
host2:
  command: echo "Started"
  image: ubuntu:trusty
  ports: ['80:80']

Attaching to ansible_host1_1, ansible_ansible-container_1, ansible_host2_1
host2_1              | Started
host1_1              | Started
ansible_host1_1 exited with code 0
ansible-container_1  | ERROR! Unexpected Exception: [Errno 13] Permission denied: '/roles/test/README.md'
ansible-container_1  | to see the full traceback, use -vvv
ansible_host2_1 exited with code 0
ansible_ansible-container_1 exited with code 250
Role initialization failed.
Cleaning up and removing build container...
Cleaning up temporary directory /tmp/tmpf4u9Cz...

Tests?

I'm assuming at the moment there's no tests for ansible-container?

Opening the issue so we could possible track this progress :)

Can't find python

When I run ansible-container build , the playbook starts to play but stop at setup stage:
ansible-container_1 | fatal: [reco]: FAILED! => {"changed": false, "failed": true, "module_stderr": "/bin/sh: 1: /usr/bin/python: not found\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}

Any suggestion?

Base image, building, environment vars, and image layer caching?

The example only shows downloading images then adding stuff on top of the image. Is it possible to just build an image from container.yaml, then use main.yaml for building of an fresh blank image? Can we use equivalent of FROM in main.yaml?

There are many scenarios to do this, especially if a base line container is built by Ops for security, and an application specific image is built inheriting a secure Ops base container.

Also, when building, each task has their own image layer? So this way we don't have to rebuild a package manifest (e.g. requirements.txt, Gemfile, package.json, bower.json, etc.) each and every time there is a rebuild.

Can we configure vars in container environment that can inherited from the host environment? Use environment variables from the shell in the main.yaml and container.yaml?

Unable to run ansible-container init

Hey,

I get following errors running ansible-container (Git SHA id: 429dcc5):

  $ ansible-container init
  Traceback (most recent call last):
    File "/home/asemt/coding/python/ansible-container-venv/bin/ansible-container", line 9, in <module>
      load_entry_point('ansible-container==0.1', 'console_scripts', 'ansible-container')()
    File "/home/asemt/coding/python/ansible-container-venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point
      return get_distribution(dist).load_entry_point(group, name)
    File "/home/asemt/coding/python/ansible-container-venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
      return ep.load()
    File "/home/asemt/coding/python/ansible-container-venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
      return self.resolve()
    File "/home/asemt/coding/python/ansible-container-venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
      module = __import__(self.module_name, fromlist=['__name__'], level=0)
  ImportError: No module named container.cli

I followed these instructions to install ansible-container inside a virtualenv on a Ubuntu 14.04.4 LTS machine.

Authentication or permission failure when trying to build (Support Docker 1.12)

I recently switched over to using the base container at [1] and now hit the following error during build:

ansible-container_1  | TASK [setup] *******************************************************************
ansible-container_1  | fatal: [foreman]: UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo /opt/app-root/ansible-tmp-1467324924.51-165209676475316 `\" && echo ansible-tmp-1467324924.51-165209676475316=\"` echo /opt/app-root/ansible-tmp-1467324924.51-165209676475316 `\" ), exited with result 1", "unreachable": true}

I have tried placing ansible.cfg in my ansible/ directory and setting environment variables but I cannot seem to figure out what makes this container special and how to get around this error.

[1] https://github.com/sclorg/rhscl-dockerfiles/tree/master/centos7.rh-ror41

Docker cli in orchestration container depends on, but doesn't include shared libs

Getting the following exception when trying to gather facts in the first ansible play within the ''ansible_container'' orchestration container:

ansible-container_1  | Using /ansible-container/ansible/ansible.cfg as config file
ansible-container_1  | Loaded callback default of type stdout, v2.0
ansible-container_1  |
ansible-container_1  | PLAYBOOK: main.yml *************************************************************
ansible-container_1  | 2 plays in main.yml
ansible-container_1  |
ansible-container_1  | PLAY [host1] ********************************************************************
ansible-container_1  |
ansible-container_1  | TASK [setup] *******************************************************************
ansible-container_1  | /usr/bin/docker: error while loading shared libraries: libapparmor.so.1: cannot open shared object file: No such file or directory
ansible-container_1  | An exception occurred during task execution. The full traceback is:
ansible-container_1  | Traceback (most recent call last):
ansible-container_1  |   File "/src/ansible/lib/ansible/executor/task_executor.py", line 124, in run
ansible-container_1  |     res = self._execute()
ansible-container_1  |   File "/src/ansible/lib/ansible/executor/task_executor.py", line 411, in _execute
ansible-container_1  |     self._connection = self._get_connection(variables=variables, templar=templar)
ansible-container_1  |   File "/src/ansible/lib/ansible/executor/task_executor.py", line 636, in _get_connection
ansible-container_1  |     connection = self._shared_loader_obj.connection_loader.get(conn_type, self._play_context, self._new_stdin)
ansible-container_1  |   File "/src/ansible/lib/ansible/plugins/__init__.py", line 349, in get
ansible-container_1  |     obj = obj(*args, **kwargs)
ansible-container_1  |   File "/src/ansible/lib/ansible/plugins/connection/docker.py", line 77, in __init__
ansible-container_1  |     docker_version = self._get_docker_version()
ansible-container_1  |   File "/src/ansible/lib/ansible/plugins/connection/docker.py", line 116, in _get_docker_version
ansible-container_1  |     cmd_output = subprocess.check_output(cmd)
ansible-container_1  |   File "/usr/local/lib/python2.7/subprocess.py", line 573, in check_output
ansible-container_1  |     raise CalledProcessError(retcode, cmd, output=output)
ansible-container_1  | CalledProcessError: Command '['/usr/bin/docker', 'version']' returned non-zero exit status 127
ansible-container_1  |
ansible-container_1  | fatal: [host1]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
ansible-container_1  |

Seems like it's breaking on attempts to begin connection to remote docker container, as those libs are not part of the container itself, per the included volumes in the template.

This is all being run from a clean xenial64 host.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.