with_fileglob returns files from outside of container

11 views
Skip to first unread message

dr...@endlessm.com

unread,
Dec 24, 2019, 8:41:30 AM12/24/19
to molecule-users
Hi,

I'm beginning to use Ansible for configuring local installations. I am not using the network mode, instead using "connection: local".

Everything looks really good so far and I like the way molecule can help test my roles in a variety of environments. Thanks for the hard work developing all these tools!

However, I'm running into some unexpected behaviour. When molecule is testing my role inside a container, the following debug task returns files from the host system, outside of the container.

- name: debug...
  debug:
    msg: "{{ item }}"
  with_fileglob:
    - "/usr/share/*"


That seems weird. One of the reasons that Molecule seems really cool is it allows me to escape the details of the host, and test under the precise deployment environment as defined by the containers which it tests in. But this is returning files from the host?

Is it possible to configure Molecule to run Ansible in the true native environment within the container? Such that the above snippet would return a list of files from the container.

Thanks
Daniel

syhR8

unread,
Dec 24, 2019, 9:10:58 AM12/24/19
to molecule-users
Hello Daniel,

This is an Ansible thing rather than a molecule thing. The with_fileglob directive will only return files from the control host. Here's some Discussion...


Basically your best bet is to use the find module and then process the list of file in another task.

Rhys

Daniel Drake

unread,
Dec 25, 2019, 12:22:44 AM12/25/19
to syhR8, molecule-users
Thanks for the quick response.
I see. Since my usage of Ansible is restricted to local execution via
"connection: local", there is no separate control host during normal
runs of my playbooks and roles.

However, when I add molecule into the picture, it seems that it ends
up using the Ansible version from the host system, instead of the
version I have in the container where the playbook would normally be
run (in local mode).

That's not what I was hoping for. The with_fileglob is one hiccup
there, but in general, I know from my colleagues' long term use of
Ansible that on occasion over different Ansible version upgrades,
standard modules change behaviour in subtle ways that can affect the
overall meaning of the playbook (usually when unintentional behaviour
was accidently being relied upon). I was hoping that by throwing a
bunch of containers at molecule, I'd be able to test a range of
different Ansible versions in their native (local) environment within
the containers in order to catch such occurrences.

Is it possible to configure Molecule to execute Ansible within the
container? If not, would this be a feature request worth discussing?

Thanks
Daniel
Reply all
Reply to author
Forward
0 new messages