Creating /etc/hosts on the fly stopped working via foreman UI


Just wondering if anone else have observed the following.

Foreman: Version 1.13.4
OS: Ubuntu 16.04

I have a bunch of servers and I want to create /etc/hosts on all of them,
containing all hosts from my inventory.
The inventory is dynamically fetched using by
Guido Günther. This works properly.

I created a task like this (slightly simplified for readability)

  • name: Populate /etc/hosts
    lineinfile: dest=/etc/hosts line="{{
    hostvars[item]['foreman_facts']['ansible_em3::ipv4::address'] }} {{ item }}
    with_items: "{{ groups['all'] }}"

Now here's the thing: If I run my tasks using the CLI, i.e.
'ansible-playbook site.yml' it works okay; all hosts are found and placed
in the 'items' array.
But if I run the play by using the 'Play ansible roles' in the foreman UI,
only the host that the playbook is running on is in the array.

So I included a debug statement in the play:

  • name: debug
    debug: msg={{ groups['all'] }}

When running the CLI version:

TASK [hosts : debug] ******************************
ok: [somehost] => {
"changed": false,
"msg": [


So all the hosts in the hostgroup 'all', including the one the playbook is
applied to, are shown.

Now I run the same plays from the foreman UI:

TASK [hosts : debug] ****************************
ok: [somehost] => {
"changed": false,
"msg": [

It only shows itself, and not any of the other hosts. I am sure this worked previously. But now it appears the contents of groups differ depending on how the playbook run is triggered.

Any ideas would be appreciated.