# shell module  variables

**URL:** <https://forum.ansible.com/t/shell-module-variables/34300>\
**Category:** Ansible Project\
**Created:** [December 8, 2020, 2:09pm UTC](https://forum.ansible.com/t/shell-module-variables/34300 "2020-12-08T14:09:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manoj\_Chander](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Manoj\_Chander](https://forum.ansible.com/u/Manoj_Chander)\
**Post date:** [December 8, 2020, 2:09pm UTC](https://forum.ansible.com/t/shell-module-variables/34300/1 "2020-12-08T14:09:49Z")

</div>

Im trying to read a file line by line and pass it to a shell module  
Is this completely wrong or i just have to find a way to make the wildcard and string to match .

- name: remove older files  
shell: ls “_{{item}}.jar_”  
with\_lines: cat file11/branches.txt

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 8, 2020, 2:12pm UTC](https://forum.ansible.com/t/shell-module-variables/34300/2 "2020-12-08T14:12:46Z")

</div>

> Im trying to read a file line by line and pass it to a shell module  
> Is this completely wrong or i just have to find a way to make the wildcard and string to match .
> 
> - name: remove older files  
> shell: ls "\*{{item}}.jar\*"  
> with\_lines: cat file11/branches.txt

Why don't you remove the files immediately with the file module?

Shell module shall be last resort.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Manoj\_Chander](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Manoj\_Chander](https://forum.ansible.com/u/Manoj_Chander)\
**Post date:** [December 8, 2020, 2:31pm UTC](https://forum.ansible.com/t/shell-module-variables/34300/3 "2020-12-08T14:31:20Z")

</div>

I couldnt search using matching string . in the below case it runs fine without the wildcards \* , but with wildcards it fails . tried few other approaches .cdnt find a proper solution

- name: Find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz  
find:  
paths: /home/tagit/test  
patterns: ‘_“{{item}}”_’  
with\_lines: cat file11/branches.txt

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 8, 2020, 2:37pm UTC](https://forum.ansible.com/t/shell-module-variables/34300/4 "2020-12-08T14:37:51Z")

</div>

> I couldnt search using matching string . in the below case it runs fine without the wildcards \* , but with wildcards  
> it fails . tried few other approaches .cdnt find a proper solution
> 
> - name: Find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz  
> find:  
> paths: /home/tagit/test  
> patterns: '\*"{{item}}"\*'  
> with\_lines: cat file11/branches.txt

Drop the " as they will be literally passed to the module. Jinja variables work the same in ' as in ".

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 15, 2020, 2:44pm UTC](https://forum.ansible.com/t/shell-module-variables/34300/5 "2020-12-15T14:44:57Z")

</div>

Alternate solutions aside, your issue is with shell globbing, you are  
quoting the \*

shell: ls "\*{{item}}.jar\*"

vs

shell: ls \*{{item}}.jar\*
