# When Condition use with Variables

**URL:** <https://forum.ansible.com/t/when-condition-use-with-variables/34864>\
**Category:** Ansible Project\
**Created:** [March 26, 2021, 12:25pm UTC](https://forum.ansible.com/t/when-condition-use-with-variables/34864 "2021-03-26T12:25:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pravin\_V](https://avatars.discourse-cdn.com/v4/letter/p/c68b51/32.png) [@Pravin\_V](https://forum.ansible.com/u/Pravin_V)\
**Post date:** [March 26, 2021, 12:25pm UTC](https://forum.ansible.com/t/when-condition-use-with-variables/34864/1 "2021-03-26T12:25:22Z")

</div>

Hello Everyone,

I’ve a task -

- name: Device Description  
uri:  
url: “{{ URL }}/api-db?username={{ USERNAME }};password={{ PASSWORD }};cmds=mget+\*+{{ display\_name }}+sys+SNMPv2-MIB.sysDescr”  
validate\_certs: no  
method: GET  
return\_content: yes  
register: get\_descriptions

Debug Output

- debug: msg=“{{ get\_descriptions.content }}”

ok: [localhost] =\>  
msg: |-  
sw01 sys SNMPv2-MIB.sysDescr = Cisco IOS C2960S (C2960S-UNIVERSALK9-M) Version 12.2(55)SE7 RELEASE (fc1)

I’m able to configure the when to run only when - Cisco IOS C2960S found in the output

- debug: msg=“{{ get\_descriptions.content }}”  
when: “‘Cisco IOS C2960S’ in get\_descriptions.content”

I’ve created a devices.yml

---

<div class="post-metadata">

**Author:** ![Pravin\_V](https://avatars.discourse-cdn.com/v4/letter/p/c68b51/32.png) [@Pravin\_V](https://forum.ansible.com/u/Pravin_V)\
**Post date:** [March 29, 2021, 7:37am UTC](https://forum.ansible.com/t/when-condition-use-with-variables/34864/2 "2021-03-29T07:37:16Z")

</div>

Hello Everyone,  
Please advise.
