Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Given a directory structure like this:
- [user@testbox01 test]$ ls -al /app/psoft/test/*
- /app/psoft/test/12.1.2.00:
- total 12
- drwxrwxr-x. 2 psoft psoft 4096 Feb 19 16:41 .
- drwxrwxr-x. 4 psoft psoft 4096 Feb 19 15:08 ..
- -rw-rw-r--. 1 psoft psoft 54 Feb 19 16:41 list.txt
- /app/psoft/test/12.1.3.00:
- total 12
- drwxrwxr-x. 2 psoft psoft 4096 Feb 19 16:41 .
- drwxrwxr-x. 4 psoft psoft 4096 Feb 19 15:08 ..
- -rw-rw-r--. 1 psoft psoft 12 Feb 19 16:41 context.xml
- test.yml playbook:
- - hosts: all
- tasks:
- - name: gather list of files
- shell: ls {{ item }}
- register: files
- with_items:
- - /app/psoft/test/*/list.txt
- - /app/psoft/test/*/context.xml
- - name: use shell to print list of file paths
- shell: "echo {{ item }}"
- with_items: "{{files.stdout_lines}}"
- output is:
- [user@ansibleserver01 ansible]$ ansible-playbook -i testing-inventory playbook_playground/test.yml --limit testbox01
- PLAY ***************************************************************************
- TASK [setup] *******************************************************************
- ok: [testbox01]
- TASK [gather list of files] ****************************************************
- changed: [testbox01] => (item=/app/psoft/test/*/list.txt)
- changed: [testbox01] => (item=/app/psoft/test/*/context.xml)
- TASK [use shell to print list of file paths] ***********************************
- [DEPRECATION WARNING]: Skipping task due to undefined attribute, in the future this will be a fatal error.. This feature will
- be removed in a future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
- PLAY RECAP *********************************************************************
- testbox01 : ok=2 changed=1 unreachable=0 failed=0
- Expected result:
- it should just print a list of files:
- /app/psoft/test/12.1.2.00/list.txt
- /app/psoft/test/12.1.3.00/context.xml
Advertisement
Add Comment
Please, Sign In to add comment