ansible / ansible-modules-core

Ansible modules - these modules ship with ansible
1.3k stars 1.95k forks source link

docker_container module - "Error connecting container to network" #5171

Closed relvira closed 7 years ago

relvira commented 8 years ago
ISSUE TYPE

docker_container

ANSIBLE VERSION
ansible 2.1.2.0
  config file = /Users/ret/Projects/servers/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION
[defaults]
inventory = ./inventory%
OS / ENVIRONMENT

OSX 10.10.5 (Yosemite) and OSX Sierra

SUMMARY

When trying to create docker containers from an ansible playbook and adding them to a docker network previously created from another playbook to give this container a static IP address I'm getting an error saying: "Error connecting container to network privnet - connect_container_to_network() got an unexpected keyword argument 'ipv4_address'"

STEPS TO REPRODUCE

Create network playbook:

- name: Create private network
  command: docker network create --subnet=192.168.100.0/24 --ip-range=192.168.100.0/24 --gateway=192.168.100.1 -o parent=eth0 privnet
  when: privnet is defined and dockernets.stdout.find(privnet.name) == -1

Create docker container playbook:


---
- file: path=/shared/config/plex state=directory mode=0755 owner=797 recurse=true
- name: plex in docker
  docker_container:
    name: "plex"
    hostname: "box1plex"
    image: timhaak/plex
    state: started
    restart_policy: always
    pull: true
    networks:
        - name: privnet
          ipv4_address: 192.168.100.10
    purge_networks: yes
    log_driver: syslog
    log_opt:
      tag: "plex"
    volumes:
    - /shared/config/plex:/config
    - /shared/plex:/data
EXPECTED RESULTS

I expect a successful container creation instead of an error.

ACTUAL RESULTS
TASK [plex : plex in docker] ***************************************************
task path: /Users/ret/Projects/servers/roles/plex/tasks/main.yml:3
<box.mydomain.com> ESTABLISH SSH CONNECTION FOR USER: ret
<box.mydomain.com> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ret -o ConnectTimeout=10 -o ControlPath=/Users/ret/.ansible/cp/ansible-ssh-%h-%p-%r box.mydomain.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1475741968.88-156551952368602 `" && echo ansible-tmp-1475741968.88-156551952368602="` echo $HOME/.ansible/tmp/ansible-tmp-1475741968.88-156551952368602 `" ) && sleep 0'"'"''
<box.mydomain.com> PUT /var/folders/7t/0myxzv9j64z0y6r2vl3wwg6m0000gn/T/tmpWiTHhW TO /home/ret/.ansible/tmp/ansible-tmp-1475741968.88-156551952368602/docker_container
<box.mydomain.com> SSH: EXEC sftp -b - -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ret -o ConnectTimeout=10 -o ControlPath=/Users/ret/.ansible/cp/ansible-ssh-%h-%p-%r '[box.mydomain.com]'
<box.mydomain.com> ESTABLISH SSH CONNECTION FOR USER: ret
<box.mydomain.com> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ret -o ConnectTimeout=10 -o ControlPath=/Users/ret/.ansible/cp/ansible-ssh-%h-%p-%r box.mydomain.com '/bin/sh -c '"'"'chmod u+x /home/ret/.ansible/tmp/ansible-tmp-1475741968.88-156551952368602/ /home/ret/.ansible/tmp/ansible-tmp-1475741968.88-156551952368602/docker_container && sleep 0'"'"''
<box.mydomain.com> ESTABLISH SSH CONNECTION FOR USER: ret
<box.mydomain.com> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ret -o ConnectTimeout=10 -o ControlPath=/Users/ret/.ansible/cp/ansible-ssh-%h-%p-%r -tt box.mydomain.com '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-prfzskmhsxhsivtoucrzsgcloglldjbv; LANG=es_ES.UTF-8 LC_ALL=es_ES.UTF-8 LC_MESSAGES=es_ES.UTF-8 /usr/bin/python /home/ret/.ansible/tmp/ansible-tmp-1475741968.88-156551952368602/docker_container; rm -rf "/home/ret/.ansible/tmp/ansible-tmp-1475741968.88-156551952368602/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && sleep 0'"'"''
fatal: [box.mydomain.com]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"api_version": null, "blkio_weight": null, "cacert_path": null, "capabilities": null, "cert_path": null, "command": null, "cpu_period": null, "cpu_quota": null, "cpu_shares": null, "cpuset_cpus": null, "cpuset_mems": null, "debug": false, "detach": true, "devices": null, "dns_opts": null, "dns_search_domains": null, "dns_servers": null, "docker_host": null, "entrypoint": null, "env": null, "env_file": null, "etc_hosts": null, "exposed_ports": null, "filter_logger": false, "force_kill": false, "groups": null, "hostname": "box1plex", "image": "timhaak/plex", "interactive": false, "ipc_mode": null, "keep_volumes": true, "kernel_memory": null, "key_path": null, "kill_signal": null, "labels": null, "links": null, "log_driver": "syslog", "log_opt": {"tag": "plex"}, "log_options": {"tag": "plex"}, "mac_address": null, "memory": "0", "memory_reservation": null, "memory_swap": null, "memory_swappiness": null, "name": "plex", "network_mode": null, "networks": [{"id": "ab1a4406681e5fef4eef6409c6819615912b4b3c6ac5e6d0161b744a96d981d1", "ipv4_address": "192.168.100.10", "name": "privnet"}], "oom_killer": null, "paused": false, "pid_mode": null, "privileged": false, "published_ports": null, "pull": true, "purge_networks": true, "read_only": false, "recreate": false, "restart": false, "restart_policy": "always", "restart_retries": 0, "security_opts": null, "shm_size": null, "ssl_version": null, "state": "started", "stop_signal": null, "stop_timeout": null, "timeout": null, "tls": null, "tls_hostname": null, "tls_verify": null, "trust_image_content": false, "tty": false, "ulimits": null, "user": null, "uts": null, "volume_driver": null, "volumes": ["/shared/config/plex:/config", "/shared/plex:/data"], "volumes_from": null}, "module_name": "docker_container"}, "msg": "Error connecting container to network privnet - connect_container_to_network() got an unexpected keyword argument 'ipv4_address'"}

Cheers, R.

ansibot commented 8 years ago

@ansible ping, this issue is waiting for your response. click here for bot help

ansibot commented 8 years ago

@ansible, ping. This issue is still waiting on your response. click here for bot help

pezzak commented 7 years ago

+1 Faced with the same issue on ansible 2.2.0.0. Same playbook was executed on two hosts: on the first - success executed, on the second failed with error above.

ansibot commented 7 years ago

@ansible, ping. This issue is still waiting on your response. click here for bot help

pezzak commented 7 years ago

@relviratellez, i've resolved my issue by updating docker-py on the server.

In the guide:

Using the docker modules requires having docker-py installed on the host running Ansible. You will need to have >= 1.7.0 installed.

pip install 'docker-py>=1.7.0'

relvira commented 7 years ago

@pezzak Thanks for the headsup, I'll try to upgrade docker-py as soon as I can.

Cheers!

Dirk-c-Walter commented 7 years ago

Faced with the same issue on ansible 2.2.0.0-1. Docker-py 1.7.2 is installed on the target, I don't specify the ip4 address but still get this issue.

- name: Create the DIRK network
  docker_network:
    name: dirkNet
    appends: yes

------

- name: Ensure Redis is installed
  become: true
  docker_container:
    name: redis
    image: '{{ image_redis_full }}'
    docker_api_version: "{{ docker_api_version }}"
    networks:
    - name: dirkNet
    exposed_ports:
    - 6379
    published_ports:
    - 6379:6379
    state: started
    log_opt:
      max-size: '{{ dirk_redis_log_file_size }}'
      max-file: '{{ dirk_redis_log_file_roll }}'
  tags:
  - dirk_router
  - dirk

I need a fix or workaround. :(

pezzak commented 7 years ago

@Dirk-c-Walter maybe you have a typo?

docker_network: name: dirkNet

networks:

  • name: dikNet
Dirk-c-Walter commented 7 years ago

@pezzak Nah I changed the names when copy and pasting the code over. good catch though :)

FYI when introducing a typo deliberately the error becomes a

"...raise errors.NotFound(e, response, explanation=explanation)\r\ndocker.errors.NotFound: 404 Client Error: Not Found (\"network dNet not found\")\r\n", "msg": "MODULE FAILURE"}"

without typos the error is the same as you get:

"FAILED! => {"changed": false, "failed": true, "msg": "Error connecting container to network dirkNet - connect_container_to_network() got an unexpected keyword argument 'ipv4_address'"}"

What version of docker-py are you using to bypass this problem?

Dirk-c-Walter commented 7 years ago

Ok workaround found it needs docker-py 1.9.0 to be installed as that adds the ipv4_address argument. If you install 1.10.x you will find that ansible thinks it is too old and so will refuse to run...

ansibot commented 7 years ago

@ansible, ping. This issue is still waiting on your response. click here for bot help

arnabsinha4u commented 7 years ago

Faced similar issue with 2.2 of ansible and docker-py 1.7. Tried the same as per documentation, gives and error of IPAddress - connect_container_to_network() got an unexpected keyword argument 'ipv4_address'"

Upgrade to docker-py1.10, similar issue as mentioned by @Dirk-c-Walter above. However, should be fixed structurally since advanced versions of docker-py have been released already and larger rollouts are constrained by this restrictions. It also introduces quite a lot of dependency management in the requirements file for playbooks and itsm processes.

ansibot commented 7 years ago

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

jaywon commented 7 years ago

Confirmed docker-py 1.9.0 fixes the referenced issue. Dropped this into my playbook:

    - name: Install docker-py python module
      pip:
        name: docker-py
        version: "1.9.0"
ansibot commented 7 years ago

This issue was migrated to https://github.com/ansible/ansible/issues/29608