Ansible Gathering Facts not working

ansible

Everytime I run a playbook, ansible will install the packages again and again, even thought it is installed, so how does it work actually?

ansible-playbook -i hosts  site.yml
GATHERING FACTS *************************************************************** 
ok: [192.168.0.2]

TASK: [Install via apt] *************************************** 
changed: [192.168.0.2] => (item=build-essential,python-dev,python-software-properties,python-setuptools)

My cookbook (Tasks):

 name: Install via apt
  action: apt pkg=$item
  with_items:
    - build-essential
    - python-dev
    - python-software-properties

Best Answer

I can't reproduce your error with this playbook:

- hosts: 10.0.0.2
  sudo: yes

  tasks:

    - name: Install via apt
      action: apt pkg=$item
      with_items:
         - build-essential
         - python-dev
         - python-software-properties

As expected, consecutive executions of the playbook are idempotent:

$ ansible-playbook pkg.playbook -K
sudo password:

PLAY [10.0.0.2] *********************

GATHERING FACTS *********************
ok: [10.0.0.2]

TASK: [Install via apt] *********************
ok: [10.0.0.2] => (item=build-essential,python-dev,python-software-properties)

PLAY RECAP *********************
10.0.0.2                       : ok=2    changed=0    unreachable=0    failed=0