r/ansible•
campee

Anyone using ansible-container to build docker images?

If so, maybe someone could help me with this error as the only meaningful result I can find on Google is a stackoverflow post where someone with this exact issue asks how to fix it but didn't get a response other than "hey me too".

I'm just trying to build a simple container from a role that contains a single task: install httpd via yum

Every time I try to build my container I get this error, which seems to be complaining about the lack of a Dockerfile (isn't that.. the whole point?)

$ 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=http-server
Building service...     project=http-server service=web

PLAY [web] *********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [web]

TASK [httpd : Install HTTPD] ***************************************************
changed: [web]

PLAY RECAP *********************************************************************
web                        : ok=2    changed=1    unreachable=0    failed=0

Applied role to service role=httpd service=web
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 399, in conductor_commandline
    **params)
  File "/_ansible/container/__init__.py", line 19, in __wrapped__
    return fn(*args, **kwargs)
  File "/_ansible/container/core.py", line 827, in conductorcmd_build
    with_name=is_last_role)
  File "/_ansible/container/docker/engine.py", line 105, 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 682, in commit_role_as_layer
    return to_commit.commit(**commit_data).id
  File "/usr/lib/python2.7/site-packages/docker/models/containers.py", line 111, in commit
    **kwargs)
  File "/usr/lib/python2.7/site-packages/docker/utils/decorators.py", line 19, in wrapped
    return f(self, resource_id, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/docker/api/container.py", line 131, in commit
    json=True)
  File "/usr/lib/python2.7/site-packages/docker/api/client.py", line 226, in _result
    self._raise_for_status(response)
  File "/usr/lib/python2.7/site-packages/docker/api/client.py", line 222, 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: 400 Client Error: Bad Request ("file with no instructions.")
Conductor terminated. Cleaning up.      command_rc=1 conductor_id=72f8ed1066757eb0fd8ad08a11cc1389a8ea43b20acefb4ae8b909b4f38ff3f5 save_container=False
ERROR   Conductor exited with status 1

Posted Jul 16, 2020, 5:56 AM UTC · edited

33
retr0h•

I thought it was cool at first but found it wasn’t really worth the effort.

2
lehoule•

Isn't it deprecated? https://github.com/ansible/ansible-container.

They tell you to use https://github.com/ansible-community/ansible-bender

There is also a connection that lets you connect to a docker container directly like any server: https://stackoverflow.com/questions/47600633/specify-docker-containers-in-etc-ansible-hosts-file

So you can use docker_container module to create your container and then connect to it with the docker connection. Pretty amazing :)

1
geerlingguy•

Ansible container is deprecated, and it always had a bit of a growing pain and wasn't fully functional out of the box.

I just use Ansible with the docker connection to build containers in some cases, like https://github.com/geerlingguy/solr-container

In other cases, I use a Dockerfile and build the image with docker_image, and deploy it with Docker Compose or into Kubernetes with the k8s module, or manage it with docker_container.

1