Deploying Docker images using Ansible

Viewed 1564

After reviewing this amazing forum, i thought it's time to join in...

I'm having issue with a playbook that deploys multiple Dockers.

  • My Ansible version is: 2.5.1
  • My Python version is 3.6.9
  • My Linux Images are 18.04 from the site: OSboxes.

Docker service is installed and running on both of the machines.

According to this website, all you need to do is follow the instructions and everything will work perfectly. :)

https://www.techrepublic.com/article/how-to-deploy-a-container-with-ansible/

(The playbook i use is in the link above)

but after following the steps, and using the playbook, i've got this error.

TASK [Pull default Docker image] ******************************************************************************************************
fatal: [192.168.1.38]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (docker_image) module: source Supported parameters include: api_version, archive_path, buildargs, cacert_path, cert_path, container_limits, debug, docker_host, dockerfile, filter_logger, force, http_timeout, key_path, load_path, name, nocache, path, pull, push, repository, rm, ssl_version, state, tag, timeout, tls, tls_hostname, tls_verify, use_tls"}

I'll be happy for your support on this issue.

4 Answers

The source: pull option was added in Ansible 2.8. Since you are using Ansible 2.5.1, that option is not available.

You can either use a later version, 2.8 or above, or just remove that line from your playbook and it should work:

- name: Pull default Docker image
  docker_image:
    name: "{{ default_container_image }}"

You won't have the guarantee that the image has been newly pulled from a registry. If that's important in your case, you can remove any locally cached version of the image first:

- name: Remove Docker image
  docker_image:
    name: "{{ default_container_image }}"
    state: absent

- name: Pull default Docker image
  docker_image:
    name: "{{ default_container_image }}"

So according to the doc of docker_image module of Ansible 2.5, there is indeed no parameter source.

Nevertheless, the doc of version 2.9 tells us it has been "added in 2.8"! So you have to update you Ansible version to be able to run the linked playbook as-is. That's you best option.

Otherwise, another option would be to keep your version 2.5 and simply remove the line 38.

(-)        source: pull

But I don't know how was the default behaviour before 2.8, so I cannot garanty you that it will do what you expect!

Finally, got this playbook to sing! :)

I did the following.

  1. upgraded the Ansibe version, so now it's running on version: 2.9.15.
  2. my python3 version is:3.6.9

After upgrading the Ansible to the version i've mentioned above, i got and error message: Failed to import the required python library (Docker SDK for Python (python >==2.7) or docker-py (python 2.6)) on osboxes(this is my machine) python...

so, after Googling this error, i found this URL:

https://neutrollized.blogspot.com/2018/12/cannot-have-both-docker-py-and-docker.html

SO, i decided to remove the docker from my machines, including the python that was installed using pip (i used the command pip-list to see if there is docker installed, and remove it using: pip uninstall).

After removing the Docker from my machines, i added the playbook one more play. install docker-compose (that's what solve my problem, and it took care of the python versions).

Just follow the URL i attached in my answer.

According the error message in Ansible module docker_image a parameter seems to be used, which is not part of the parameters implemented for that module (yet). Also the error message lists already the parameter which are available. Same as in the documentation for the module.

An other possible reason might be that the line indent for some of the parameters isn't correct.

Related