# Help with Conditions

**URL:** <https://forum.ansible.com/t/help-with-conditions/32851>\
**Category:** Ansible Project\
**Created:** [May 5, 2020, 11:37am UTC](https://forum.ansible.com/t/help-with-conditions/32851 "2020-05-05T11:37:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Foley](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@David\_Foley](https://forum.ansible.com/u/David_Foley)\
**Post date:** [May 5, 2020, 11:37am UTC](https://forum.ansible.com/t/help-with-conditions/32851/1 "2020-05-05T11:37:55Z")

</div>

Hi All,

Just wondering is their a better way of doing the Following?

`

`

---

<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:** [May 5, 2020, 1:39pm UTC](https://forum.ansible.com/t/help-with-conditions/32851/2 "2020-05-05T13:39:49Z")

</div>

I would use vars to simplify the tasks themselves, alternatively you  
could use a block to establish the common condition

- name: run when not powered off  
&nbsp;&nbsp;&nbsp;vmware\_guest\_powerstate:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hostname: '{{ mdb\_console.json.0[resolved\_name]}}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;powerstate: '{{ (json\_file.stdout | from\_json).power\_state}}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console\_defined : '{{ mdb\_console.json.0['console'] is defined}}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resolved\_name: '{{ console\_defined|ternary("console", "vconsole")}}'  
&nbsp;&nbsp;when: 'powerstate != "poweredOff"'
