【问题标题】:Ansible apt module showing "item changed" when I don't think it didAnsible apt 模块在我认为没有显示“项目已更改”时显示
【发布时间】:2017-01-04 21:09:32
【问题描述】:

我正在尝试使用 Ansible 安装 Apache2。我有一个 Apache 的角色和处理程序。

我的剧本 (site.yml) 包含:

---
- hosts: webservers
  remote_user: ansrun
  become: true
  become_method: sudo

Ansible 角色文件包含:

---
- name: Install Apache 2
  apt: name={{ item }} update_cache=yes state=present
  with_items:
    - apache2
  when: ansible_distribution == "Ubuntu"

- name: Enable mod_rewrite
  apache2_module: name=rewrite state=present
  notify:
    - reload apache2

每当我运行 playbook 时,我都会收到此消息,但没有任何变化。

changed: [10.0.1.200] => (item=[u'apache2'])

我认为这与条件有关。

【问题讨论】:

  • 你能发布整个输出吗?也将其添加到您的游戏中。 - debug: var=ansible_distribution

标签: ansible ansible-playbook ansible-2.x


【解决方案1】:

您遇到了在 Ansible 2.2.0 中引入的 problem(并在 2.2.1 中修复)。

使用update_cache=yes 时,apt 模块会在 APT 缓存更新发生时返回 changed-status,而不仅仅是在实际软件包升级时。

您需要将 Ansible 升级到 2.2.1 版本(1 月 16 日正式发布)

您需要执行以下操作之一:

  • 将 Ansible 至少升级到 2.2.1(目前处于候选发布状态,在 PyPI 中不可用,因此您必须 run Ansible from source);
  • 将 Ansible 降级到 2.1.3;
  • 保留 Ansible 2.2.0 并将Install Apache 2 任务拆分为两个:
    • 一个仅用于缓存更新(可能将changed_when 设置为false),
    • 一个用于实际的apache2 包安装(没有update_cache=yes),调用处理程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-18
    • 2021-10-22
    • 1970-01-01
    • 2018-01-26
    • 2012-03-27
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多