简体   繁体   English

在 Docker 与 VM 上运行 Ansible

[英]Run Ansible over Docker vs VM

I want to create test environment for ansible-playbook from my PC to Linux server cluster which installs ELK on it, considering whether to run it on a container or a VM.我想为从我的 PC 到安装 ELK 的 Linux 服务器集群的 ansible-playbook 创建测试环境,考虑是在容器还是 VM 上运行它。

Obviously using docker should make the process easier and faster to facilitate, but I think there is more depth to this topic beyond the general discussion of choosing Docker versus VM , by focusing on Ansible deployments with relation to storage, networking and privileges management.显然使用 docker 应该使该过程更容易和更快地进行,但我认为除了选择 Docker 与 VM 的一般讨论之外,这个主题还有更多的深度,重点是 Ansible 与存储关系的网络管理和权限管理。

What are the considerations for running Ansible deployments on Docker container versus Virtual Machine?在 Docker 容器与虚拟机上运行 Ansible 部署的注意事项是什么?

I'd almost never target Ansible against a Docker container.我几乎永远不会针对 Docker 容器来针对 Ansible 。

Ansible's model is much more suited to targeting a VM. Ansible 的 model 更适合针对 VM。 If you have an existing Ansible playbook that's targeting a physical system or a cloud instance, a VM will be a good mirror of the operating system environment it expects, but a Docker setup will be very different.如果你有一个现有的 Ansible playbook 以物理系统或云实例为目标,那么 VM 将是它所期望的操作系统环境的良好镜像,但 Docker 设置将非常不同。

Ansible generally expects to make an ssh connection to its target host, run a Python installed there, and its changes to be reasonably persistent. Ansible 通常希望与其目标主机建立 ssh 连接,运行安装在那里的 Python,并且其更改是合理持久的。 In contrast a Docker container almost never runs an ssh daemon, frequently won't have Python, and any changes that get made will be lost as soon as the container exits.相比之下,Docker 容器几乎从不运行 ssh 守护进程,通常不会有 Python,并且一旦容器退出,所做的任何更改都会丢失。 A typical server-oriented Ansible playbook will do things like set up service configuration and init scripts, but in a Docker system there isn't an init and service configuration is generally injected.典型的面向服务器的 Ansible 剧本将执行诸如设置服务配置和初始化脚本之类的操作,但在 Docker 系统中,通常没有初始化和服务配置注入。

It's probably better here to think of a Docker container as packaging around a single process.将 Docker 容器视为围绕单个进程进行封装可能会更好。 You can use bind mounts to inject configuration from the host, and you could use Ansible on the host to start the container, but you wouldn't use Ansible to "set up" a container.您可以使用绑定挂载从主机注入配置,并且可以在主机上使用 Ansible 来启动容器,但您不会使用 Ansible 来“设置”容器。 If you need software installed in a container then using Docker's native docker build system can get this done in a reproducible way, without needing additional steps after the container is started.如果您需要在容器中安装软件,那么使用 Docker 的原生docker build系统可以以可重现的方式完成此操作,而无需在容器启动后执行其他步骤。

The one prominent exception to the "almost never" is running Molecule tests inside a container , but note that this setup does have the nature of changes being temporary and short-lived (as soon as the test is over you want to tear down the container). “几乎从不”的一个突出例外是在容器内运行 Molecule 测试,但请注意,此设置确实具有临时和短暂更改的性质(一旦测试结束,您就想拆除容器)。

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

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