简体   繁体   English

Ansible Playbook中的微小更改不会在目标主机中更新

[英]Minor change in ansible playbook does not get updated in target host

My playbook is (among other things) starting a docker container: 我的剧本(除其他事项外)正在启动Docker容器:

- name: Restart nginx container
  docker:
    name: nginx
    image: my-nginx
    state: started
    ports:
    - "{{ nginx_port }}:80"
    volumes:
    - "{{ host_socket }}:{{ container_socket }}"

This is correctly starting the container. 这是正确启动容器。 But if I decide I need to run nginx in another port, and run again the playbook, the container is not restarted. 但是,如果我决定需要在另一个端口中运行nginx ,然后再次运行剧本,则不会重新启动容器。 It seems that ansible is happy with the container being up and running, but does not verify if the rest of parameters are right. 似乎ansible对容器已启动并正在运行感到满意,但是并没有验证其余参数是否正确。

I see two options here: 我在这里看到两个选择:

  1. force a restart whenever I run the playbook, no conditions asked, so that I make sure that the latest configuration is active. 每当我运行剧本时都将强制重新启动,不要求任何条件,以便确保最新配置处于活动状态。 I do not like this because most of the time the parameters do not change. 我不喜欢这样,因为大多数时候参数不会改变。
  2. force ansible to be more accurate and check all parameters, restarting the container if whatever value has changed. 强制ansible更加准确,并检查所有参数,如果更改了任何值 ,则重新启动容器。 I am not sure there is such an option. 我不确定是否有这样的选择。

How can I tell ansible to be more accurate when checking the state of the container? 检查容器状态时,如何告诉ansible更准确?

The docker module is deprecated, I assume it must be one of its issue. docker模块已被弃用,我认为它必须是其问题之一。

Did you try the docker_container module ? 您是否尝试过docker_container模块 You will need ansible > 2.1.0 but I think it's worth a try. 您需要ansible> 2.1.0,但我认为值得尝试。

It seems that ansible is happy with the container being up and running, but does not verify if the rest of parameters are right. 似乎ansible对容器已启动并正在运行感到满意,但是并没有验证其余参数是否正确。

Yes, because you specified state: started , and that's explicitly what that means: 是的,因为您指定了state: started ,这显然意味着:

"started" asserts that the matching containers both exist and are running, but takes no action if any configuration has changed. “启动”断言匹配的容器既存在并且正在运行,但是如果任何配置已更改,则不采取任何措施。

You probably want reloaded instead: 您可能需要reloaded

"reloaded" (added in Ansible 1.9) asserts that all matching containers are running and restarts any that have any images or configuration out of date. “重新加载”(在Ansible 1.9中添加)断言所有匹配的容器正在运行,并重新启动具有任何映像或配置已过期的容器。

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

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