included tasks do not execute when running playbook with ansible api

I have a simple test role located in /etc/ansible/roles/test/tasks/main.yml like this:

---
- roles/common/tasks/facts.yml
- include: test.yml

And I use the example code of Python API 2.0 found in Documentation. Then I’ve encountered a strange problem.

On my develop machine which is a Mac, everything works fine, but when I run it on the production machine whose operating system is CentOS 7, the two included tasks can’t be executed. Here is the output:

PLAY [Test Play] **************************************************************

TASK [setup] *******************************************************************
ok: [10.85.0.20]

TASK [test : include] **********************************************************
included: /etc/ansible/roles/common/tasks/facts.yml for 10.85.0.20

TASK [test : include] **********************************************************
included: /etc/ansible/roles/test/tasks/test.yml for 10.85.0.20

You see, it did including operation, but nothing actually executed.

And the correct output would be:

PLAY [Test Play] **************************************************************

TASK [setup] *******************************************************************
ok: [10.85.0.20]

TASK [test : include] **********************************************************
included: /Users/Jiang/projects/ecs-ansible/roles/common/tasks/facts.yml for 10.85.0.20

TASK [test : facts.d dir] ******************************************************
ok: [10.85.0.20]

TASK [test : facts file] *******************************************************
changed: [10.85.0.20]

TASK [test : get facts from pluto] *********************************************
changed: [10.85.0.20]

TASK [test : setup] ************************************************************
ok: [10.85.0.20]

TASK [test : include] **********************************************************
included: /Users/Jiang/projects/ecs-ansible/roles/test/tasks/test.yml for 10.85.0.20

TASK [test : debug] ************************************************************
ok: [10.85.0.20] => {
    "msg": "15.0"
}

Version:

  • OSX 10.11.4 beta & ansible 2.1.0 (devel 36aa89a) last updated 2016/01/18 14:48:31 (GMT +800)
  • CentOS 7.1.1503 & ansible 2.1.0 (devel 36aa89a) last updated 2016/01/18 23:05:26 (GMT +800)

Could someone help me to solve this? Thanks.

Could you provide copies of your roles/common/tasks/facts.yml and roles/test/tasks/test.yml files, so others can try to fully reproduce what you’re experiencing?

Here is the contents of the included tasks:

roles/common/tasks/facts.yml:
---
- name: facts.d dir
  file: path=/etc/ansible/facts.d state=directory

- name: facts file
  copy: src=roles/common/files/facts/preferences.fact dest=/etc/ansible/facts.d/preferences.fact

- name: get facts from pluto
  get_url: url=http://10.209.0.83:7070/api/config/ansible_facts?ip={{ ansible_default_ipv4.address }} force=yes dest=/etc/ansible/facts.d/preferences.fact
  
- setup: filter=*
roles/test/tasks/test.yml
---
- debug: msg={{ (ansible_memtotal_mb / 1024) | round }}

What versions of Python are you using on OSX vs. CentOS 7?