Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible apt module showing "item changed" when I don't think it did

I am trying to install Apache2 with Ansible. I have a role and handler for Apache.

My playbook (site.yml) contains:

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

The Ansible role file contains:

---
- 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

Whenever I run the playbook, I get this message, but nothing has changed.

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

I think this has something to do with the conditional.

like image 893
Sean Avatar asked Oct 29 '22 14:10

Sean


1 Answers

You are running into a problem introduced to Ansible 2.2.0 (and fixed in 2.2.1).

With update_cache=yes the apt module was made to return changed-status whenever APT cache update occurred, not only when the actual package was upgraded.

You need to upgrade Ansible to version 2.2.1 (released officially on Jan 16th)

You need to do one of the following:

  • upgrade Ansible to at least 2.2.1 (currently in release candidate state and not available in PyPI, so you'd have to run Ansible from source);
  • downgrade Ansible to 2.1.3;
  • retain Ansible 2.2.0 and split the Install Apache 2 task into two:
    • one for cache update only (maybe with changed_when set to false),
    • one for the actual apache2 package installation (without update_cache=yes), calling the handler.
like image 159
techraf Avatar answered Nov 11 '22 13:11

techraf