Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with_fileglob always looks up files on localhost #34497

Closed
riccardomurri opened this issue Jan 5, 2018 · 4 comments
Closed

with_fileglob always looks up files on localhost #34497

riccardomurri opened this issue Jan 5, 2018 · 4 comments
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@riccardomurri
Copy link
Contributor

ISSUE TYPE
  • Bug Report
COMPONENT NAME

with_fileglob core built-in looping feature.

ANSIBLE VERSION
ansible 2.3.2.0
  config file =
  configured module search path = Default w/o overrides
  python version = 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
CONFIGURATION

Empty ansible.cfg file.

OS / ENVIRONMENT
 $ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 17.10
Release:    17.10
Codename:   artful
SUMMARY

Looping over existing files with with_fileglob always looks up
filesystem entries on the controller host where Ansible is running,
and not on the target host.

STEPS TO REPRODUCE

Use the following playbook to reproduce:

---

- name:
  hosts: all
  gather_facts: yes

  tasks:
    - name: Make test files
      file:
        name: '/tmp/issue-test.{{item}}'
        state: touch
      with_items:
        - foo
        - bar
        - baz

    - name: List results of `with_fileglob`
      debug:
        msg: 'path={{ item }}'
      with_fileglob: '/tmp/issue-test.*'
  1. Remove any local files matching the glob pattern:

     rm -f /tmp/issue-test.*
    
  2. Run the playbook targeting any remote host -- files /tmp/issue-test.{foo.bar.baz} will be created but not listed.

EXPECTED RESULTS

I would expect with_fileglob to look up files remotely.

If this is not the intended behavior, it should be clearly stated in the docs.
(Still, I would like a way to do file globs with remote files.)

ACTUAL RESULTS

Ansible expands with_fileglob with contents of a local file lookup.
This can be seen by running the above playbook:

# ensure that no test files exist locally
$ rm /tmp/issue-test.*

# now run ansible targeting a remote host -- no files are listed
$ ansible-playbook -i "ubuntu@172.23.28.106," /tmp/issue.yml

PLAY [all] ***************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [ubuntu@172.23.28.106]

TASK [Make test files] ***************************************************************************************************************************************
changed: [ubuntu@172.23.28.106] => (item=foo)
changed: [ubuntu@172.23.28.106] => (item=bar)
changed: [ubuntu@172.23.28.106] => (item=baz)

TASK [List results of `with_fileglob`] ***********************************************************************************************************************

PLAY RECAP ***************************************************************************************************************************************************
ubuntu@172.23.28.106       : ok=2    changed=1    unreachable=0    failed=0
@ansibot
Copy link
Contributor

ansibot commented Jan 5, 2018

Files identified in the description:
None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jan 5, 2018
@sivel
Copy link
Member

sivel commented Jan 5, 2018

This is the expected behavior. with_fileglob is a lookup and as documented at http://docs.ansible.com/ansible/latest/playbooks_lookups.html

Note
Lookups occur on the local computer, not on the remote computer.

To iterate a list of files on a remote node, use the find module, register the results, and then loop over them with with_items or similar.

If you have further questions please stop by IRC or the mailing list:

@sivel sivel closed this as completed Jan 5, 2018
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Jan 5, 2018
@riccardomurri
Copy link
Contributor Author

This is the expected behavior. with_fileglob is a lookup

This information is however, nowhere to be found on the "loops" page. Everything that is stated about with_fileglob is:

with_fileglob matches all files in a single directory, non-recursively, that match a pattern. It calls Python’s glob library

(plus a warning about relative paths with roles).

I still think there should be a warning/note.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@doxxx
Copy link

doxxx commented May 31, 2018

I only learned of this by reading this issue.

zharalim added a commit to zharalim/ansible that referenced this issue Sep 9, 2018
Made the note clearer and instructed to use find module for remote operations.
Relating to ansible#34497
pull bot pushed a commit to yaplej/ansible that referenced this issue Sep 17, 2018
Made the note clearer and instructed to use find module for remote operations.
Relating to ansible#34497
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

4 participants