osx - problems using Ansible to run docker tasks on OS X -
i trying tell ansible build docker image on os x machine , error get:
$ ansible-playbook main.yml play [localhost] ************************************************************** gathering facts *************************************************************** ok: [localhost] task: [build docker image dockerfiles] *********************************** failed: [localhost] => {"changed": false, "failed": true} msg: connectionerror(protocolerror('connection aborted.', error(2, 'no such file or directory')),) fatal: hosts have failed -- aborting play recap ******************************************************************** retry, use: --limit @/users/ronny/main.retry localhost : ok=1 changed=0 unreachable=0 failed=1 this main.yml file using:
--- - hosts: localhost connection: local tasks: - name: build docker image dockerfiles docker_image: name: testimage path: test state: build my dockerfile:
# build example docker container image. busybox maintainer jeff geerling <geerlingguy@mac.com> # run command when container starts. cmd ["/bin/true”]” my docker file located in cookbook/test/dockerfile
and main.yml file located in cookbook/main.yml
i'm running on os x.
i totally lost @ point , appreciated.
edit:
in response nathanials request use -vvvv following error:
(this path set subdirectory "test")
task: [build docker image dockerfiles] *********************************** <localhost> establish connection user: ronny <localhost> remote_module docker_image name=test state=build path=test <localhost> exec ssh -c -tt -vvv -o controlmaster=auto -o controlpersist=60s -o controlpath="/users/ronny/.ansible/cp/ansible-ssh-%h-%p-%r" -o kbdinteractiveauthentication=no -o preferredauthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o passwordauthentication=no -o connecttimeout=10 localhost /bin/sh -c 'mkdir -p $home/.ansible/tmp/ansible-tmp-1433079033.35-4833710313724 && chmod a+rx $home/.ansible/tmp/ansible-tmp-1433079033.35-4833710313724 && echo $home/.ansible/tmp/ansible-tmp-1433079033.35-4833710313724' <localhost> put /var/folders/s1/g6kswg952gvg5df6wld173480000gn/t/tmp3g0piz /users/ronny/.ansible/tmp/ansible-tmp-1433079033.35-4833710313724/docker_image <localhost> exec ssh -c -tt -vvv -o controlmaster=auto -o controlpersist=60s -o controlpath="/users/ronny/.ansible/cp/ansible-ssh-%h-%p-%r" -o kbdinteractiveauthentication=no -o preferredauthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o passwordauthentication=no -o connecttimeout=10 localhost /bin/sh -c 'lang=en_us.utf-8 lc_ctype=en_us.utf-8 /usr/bin/python /users/ronny/.ansible/tmp/ansible-tmp-1433079033.35-4833710313724/docker_image; rm -rf /users/ronny/.ansible/tmp/ansible-tmp-1433079033.35-4833710313724/ >/dev/null 2>&1' failed: [localhost] => {"failed": true, "parsed": false} traceback (most recent call last): file "/users/ronny/.ansible/tmp/ansible-tmp-1433079033.35-4833710313724/docker_image", line 1852, in <module> main() file "/users/ronny/.ansible/tmp/ansible-tmp-1433079033.35-4833710313724/docker_image", line 235, in main image_id = manager.build() file "/users/ronny/.ansible/tmp/ansible-tmp-1433079033.35-4833710313724/docker_image", line 140, in build stream = self.client.build(self.path, tag=':'.join([self.name, self.tag]), nocache=self.nocache, rm=true, stream=true) file "/usr/local/lib/python2.7/site-packages/docker/client.py", line 319, in build raise typeerror("you must specify directory build in path") typeerror: must specify directory build in path openssh_6.2p2, osslshim 0.9.8r 8 dec 2011 debug1: reading configuration data /etc/ssh_config debug1: /etc/ssh_config line 20: applying options * debug1: auto-mux: trying existing master debug2: fd 3 setting o_nonblock debug2: mux_client_hello_exchange: master version 4 debug3: mux_client_forwards: request forwardings: 0 local, 0 remote debug3: mux_client_request_session: entering debug3: mux_client_request_alive: entering debug3: mux_client_request_alive: done pid = 78798 debug3: mux_client_request_session: session request sent debug1: mux_client_request_session: master session id: 2 debug3: mux_client_read_packet: read header failed: broken pipe debug2: received exit status master 0 shared connection localhost closed. fatal: hosts have failed -- aborting play recap ******************************************************************** retry, use: --limit @/users/ronny/main.retry localhost : ok=1 changed=0 unreachable=0 failed=1 in response above error, tried giving full path build directory dockerfile located
path: "/users/ronny/projects/dockers/tutorial/ansibledocker/test” then got:
task: [build docker image dockerfiles] *********************************** <localhost> establish connection user: ronny <localhost> remote_module docker_image name=test state=build path=/users/ronny/projects/dockers/tutorial/ansibledocker/test <localhost> exec ssh -c -tt -vvv -o controlmaster=auto -o controlpersist=60s -o controlpath="/users/ronny/.ansible/cp/ansible-ssh-%h-%p-%r" -o kbdinteractiveauthentication=no -o preferredauthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o passwordauthentication=no -o connecttimeout=10 localhost /bin/sh -c 'mkdir -p $home/.ansible/tmp/ansible-tmp-1433079137.87-213359153110012 && chmod a+rx $home/.ansible/tmp/ansible-tmp-1433079137.87-213359153110012 && echo $home/.ansible/tmp/ansible-tmp-1433079137.87-213359153110012' <localhost> put /var/folders/s1/g6kswg952gvg5df6wld173480000gn/t/tmplh4lln /users/ronny/.ansible/tmp/ansible-tmp-1433079137.87-213359153110012/docker_image <localhost> exec ssh -c -tt -vvv -o controlmaster=auto -o controlpersist=60s -o controlpath="/users/ronny/.ansible/cp/ansible-ssh-%h-%p-%r" -o kbdinteractiveauthentication=no -o preferredauthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o passwordauthentication=no -o connecttimeout=10 localhost /bin/sh -c 'lang=en_us.utf-8 lc_ctype=en_us.utf-8 /usr/bin/python /users/ronny/.ansible/tmp/ansible-tmp-1433079137.87-213359153110012/docker_image; rm -rf /users/ronny/.ansible/tmp/ansible-tmp-1433079137.87-213359153110012/ >/dev/null 2>&1' failed: [localhost] => {"changed": false, "failed": true} msg: connectionerror(protocolerror('connection aborted.', error(2, 'no such file or directory')),) fatal: hosts have failed -- aborting play recap ******************************************************************** retry, use: --limit @/users/ronny/main.retry localhost : ok=1 changed=0 unreachable=0 failed=1 edit #2
ok, tried doing different. instead of building image, tried start one. after diggin in lib/python2.7/site-packages/ansible/modules/core/cloud/docker/docker.py noticed in class dockermanager.init around line 558, set few environment variables:
env_host = os.getenv('docker_host') env_docker_verify = os.getenv('docker_tls_verify') env_cert_path = os.getenv('docker_cert_path') env_docker_hostname = os.getenv('docker_tls_hostname') so spat out values log file, , lo , behold, none of them being set.
then when set them directly in main.yml:
- name: start container docker: name: mydata image: busybox state: present environment: docker_host: tcp://192.168.59.103:2376 docker_tls_verify: 1 docker_cert_path: /users/ronny/.boot2docker/certs/boot2docker-vm docker_tls_hostname: boot2docker i able successful start container!
however, method did not work initial issue, build docker image.
digging further in docker_image.py noticed breaks down around line 188 (i "around" because have logging breaks don't know exact line) has following code:
images = self.client.images() so more digging , see self.client checking out docker_url @ 'unix://var/run/docker.sock'
but on @ link see /var/run/docker.sock not exist on os x, instead 1 reply said that
/var/run/docker.sock not on osx filesystem - docker daemon running inside boot2docker vm - , that's unix socket is.
that serial file not related docker socket.
oyu need talk tcp socket specified in docker_host env.
now tried setting docker_url docker_host url, description modules says:
docker_url: description: - url of docker host issue commands required: false default: unix://var/run/docker.sock aliases: []
but when set docker_host address, got error.
here main.yml
- name: build docker image dockerfiles docker_image: name: testimage # path: test path: /users/ronny/projects/dockers/tutorial/ansibledocker/test state: build docker_url: 192.168.59.103:2376 and here error:
failed: [localhost] => {"changed": false, "failed": true} msg: connectionerror(protocolerror('connection aborted.', badstatusline('\x15\x03\x01\x00\x02\x02\n',)),) fatal: hosts have failed -- aborting play recap ******************************************************************** retry, use: --limit @/users/ronny/main.retry localhost : ok=3 changed=0 unreachable=0 failed=1 any ideas?
as workaround can use proxy, "socat-container" routes request tcp address unix socket. take @ page. port 2376 on boot2docker works ipv6 , not ipv4 (i found no way change this, didn't dig deeper problem , don't idea make changes boot2docker vm). added nat translation in virtualbox localhost(ansible inventory localhost)
be careful ansible , docker-py
you need:
- ansible 1.9.2
- docker_api_version: 1.18
works me.
Comments
Post a Comment