# variable fun

**URL:** <https://forum.ansible.com/t/variable-fun/11595>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [June 1, 2012, 12:02pm UTC](https://forum.ansible.com/t/variable-fun/11595 "2012-06-01T12:02:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [June 1, 2012, 12:02pm UTC](https://forum.ansible.com/t/variable-fun/11595/1 "2012-06-01T12:02:36Z")

</div>

--Michael

> Hi,
> 
> I am using the devel branch from github.  
> Two problems for me with variables:
> 
> 1)

Thanks for testing!

Are you saying only\_if is not expanding variables or are you saying only\_if is generally not working?

Since there is a considerable amount of refactoring in 0.5, it is highly likely "only\_if" doesn't presently interpolate, which is an easy fix.

If you want to help, you could add some debug code to runner to see what the conditional (it's called conditional in runner/\_\_init\_\_.py I recall) and print that out to quickly isolate this.

> - hosts: app201:app505m  
> vars:  
> is\_cen5: "'ansible\_distribution\_version' == '5.8'"  
> is\_cen6: "'ansible\_distribution\_version' == '6.2'"  
> tasks:  
> - name: deploy centos5 specific monitoring  
> action: copy src=../monitoring/cen5\_proc.py dest=/home/mweber/proc.py owner=mweber group=users mode=0740  
> only\_if: "$is\_cen5"  
> - name: deploy centos6 specific monitoring  
> action: copy src=../monitoring/cen6\_proc.py dest=/home/mweber/proc.py owner=mweber group=users mode=0740  
> only\_if: "$is\_cen6"
> 
> This doesn't work.
> 
> TASK: [deploy centos5 specific monitoring] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> skipping: [app505]
> 
> skipping: [app201]
> 
> 2)
> 
> - hosts: app505:app201  
> user: mweber  
> sudo: True  
> tasks:  
> - name: roll out ${item}  
> action: copy src=../monitoring/$item dest=/home/mweber/$item owner=mweber group=users mode=0740  
> with\_items:  
> - cpu.py  
> - io.py  
> - proc.py  
> - guardian.py  
> - net.py
> 
> TASK: [roll out cpu.py] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> fatal: [app505] =\> file or module does not exist: ../monitoring/$item  
> fatal: [app201] =\> file or module does not exist: ../monitoring/$item

This seems to say with\_items isn't interpolating right, but it might be specific to file, I'm not sure. Please file an issue in github so we can take a look.

---

<div class="post-metadata">

**Author:** ![damaex](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@damaex](https://forum.ansible.com/u/damaex)\
**Post date:** [June 1, 2012, 1:36pm UTC](https://forum.ansible.com/t/variable-fun/11595/2 "2012-06-01T13:36:08Z")

</div>

> Thanks for testing!
> 
> Are you saying only\_if is not expanding variables or are you saying only\_if is generally not working?
> 
> Since there is a considerable amount of refactoring in 0.5, it is highly likely “only\_if” doesn’t presently interpolate, which is an easy fix.
> 
> If you want to help, you could add some debug code to runner to see what the conditional (it’s called conditional in runner/ **init**.py I recall) and print that out to quickly isolate this.

I will look into the code on the weekend. Thanks!

> This seems to say with\_items isn’t interpolating right, but it might be specific to file, I’m not sure. Please file an issue in github so we can take a look.

Will do.
