简体   繁体   English

使用 Ansible 部署 Docker 镜像

[英]Deploying Docker images using Ansible

After reviewing this amazing forum, i thought it's time to join in...回顾了这个了不起的论坛后,我想是时候加入了……

I'm having issue with a playbook that deploys multiple Dockers.我对部署多个 Docker 的剧本有疑问。

  • My Ansible version is: 2.5.1我的Ansible版本是:2.5.1
  • My Python version is 3.6.9我的Python版本是 3.6.9
  • My Linux Images are 18.04 from the site: OSboxes .我的 Linux 映像是来自站点的 18.04: OSboxes

Docker service is installed and running on both of the machines. Docker 服务已安装并运行在两台机器上。

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/ 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.我会很高兴您对这个问题的支持。

The source: pull option was added in Ansible 2.8 . source: pull选项是在Ansible 2.8中添加的。 Since you are using Ansible 2.5.1, that option is not available.由于您使用的是 Ansible 2.5.1,因此该选项不可用。

You can either use a later version, 2.8 or above, or just remove that line from your playbook and it should work:您可以使用更高版本,2.8 或更高版本,或者只是从您的剧本中删除该行,它应该可以工作:

- 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 .所以根据 Ansible 2.5 docker_image模块的文档,确实没有参数source

Nevertheless, the doc of version 2.9 tells us it has been "added in 2.8"!尽管如此, 2.9 版文档告诉我们它已“在 2.8 中添加”! So you have to update you Ansible version to be able to run the linked playbook as-is.因此,您必须更新 Ansible 版本才能按原样运行链接的剧本。 That's you best option.那是你最好的选择。

Otherwise, another option would be to keep your version 2.5 and simply remove the line 38.否则,另一种选择是保留您的版本 2.5 并简单地删除第 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!但是我不知道 2.8 之前的默认行为如何,所以我不能保证它会按照您的预期运行!

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.升级了 Ansibe 版本,所以现在它在版本:2.9.15 上运行。
  2. my python3 version is:3.6.9我的python3版本是: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...将 Ansible 升级到我上面提到的版本后,我收到错误消息:无法在osboxes (这是我的机器)python...

so, after Googling this error, i found this URL:所以,在谷歌搜索这个错误后,我找到了这个 URL:

https://neutrollized.blogspot.com/2018/12/cannot-have-both-docker-py-and-docker.html 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).所以,我决定从我的机器上删除 docker,包括使用 pip 安装的 python(我使用命令 pip-list 查看是否安装了 docker,并使用:pip uninstall 删除它)。

After removing the Docker from my machines, i added the playbook one more play.从我的机器上删除 Docker 后,我又添加了剧本。 install docker-compose (that's what solve my problem, and it took care of the python versions).安装 docker-compose (这就是解决我的问题的方法,它处理了 python 版本)。

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).根据 Ansible 模块docker_image的错误消息,似乎使用了一个参数,该参数不是为该模块实现的参数的一部分(尚未)。 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.另一个可能的原因可能是某些参数的行缩进不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM