mchinaloy
mchinaloy

Reputation: 1494

Ansible Docker Module from OSX

I am trying to use the Ansible Docker module at the moment but I am currently encountering this error when I try to run my playbook -

NameError: global name 'DEFAULT_DOCKER_API_VERSION' is not defined

I found an official bug regarding this at https://github.com/ansible/ansible-modules-core/issues/1792.

I have tried the workaround by installing docker-py but have had no joy as of yet.

Any ideas on what could be going wrong? I'm trying to run my Playbook from my local OSX host that connects to AWS.

Upvotes: 1

Views: 1759

Answers (4)

chrism
chrism

Reputation: 1661

TLDR; -e use_tls=encrypt

  • I'm using the newest dockerpy==1.5.0
  • ~/.bash_profile I have eval "$(docker-machine env default)" which will run

    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://192.168.99.100:2376"
    export DOCKER_CERT_PATH="/Users/meyers/.docker/machine/machines/default"
    export DOCKER_MACHINE_NAME="default"
    

Now that your environment is setup let me tell you the fix. The docker module needs the parameter tls=encrypt. You can supply it to each invocation of the docker module in your Ansible task or you can set it "globally" via -e use_tls=encrypt or in your playbook:

    - hosts: all
      vars:
        use_tls: 'encrypt'
      tasks:
        ...

Upvotes: 0

Jonathan Gimeno
Jonathan Gimeno

Reputation: 434

Normally it is related to the absence of pip or docker-py library.

I have this in my docker ansible role.

- name: install the required packages
  apt: pkg={{ item }} state=present update_cache=yes
  with_items:
   - python-pip

- name: Install docker-py as a workaround for Ansible issue
  pip: name=docker-py version=1.2.3

Upvotes: 0

mchinaloy
mchinaloy

Reputation: 1494

After further investigation we managed to get it to work by using -

name: Install Docker PY
pip: name=docker-py==1.1.0 

In our .yml file

Upvotes: 1

udondan
udondan

Reputation: 59969

pip is a package manager for python and installs with it. So what you want to do is installing python.

On OS X I recommend you to first install Homebrew, which is a package manager for OS X. The command to install Homebrew is

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After Homebrew is installed you can install python and along with it pip with

brew install python

Upvotes: 0

Related Questions