# Need help for ternary operator in ansible

**URL:** <https://forum.ansible.com/t/need-help-for-ternary-operator-in-ansible/33243>\
**Category:** Ansible Project\
**Created:** [June 24, 2020, 7:11am UTC](https://forum.ansible.com/t/need-help-for-ternary-operator-in-ansible/33243 "2020-06-24T07:11:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [June 24, 2020, 7:11am UTC](https://forum.ansible.com/t/need-help-for-ternary-operator-in-ansible/33243/1 "2020-06-24T07:11:29Z")

</div>

Hi Ansible Gurus ,  
i have below task :

- name: RPM EPOCH Finder  
#command: rpm -qa --qf ‘%|EPOCH?{%{EPOCH}}:{0}|\n’ {{ item.split(‘.’)[0] | regex\_replace(‘-\d+’, ‘’)}}  
command: rpm -qa --qf ‘%|EPOCH?{%{EPOCH}}:{0}|\n’ {{ item.split(‘.’)[0] | regex\_replace(‘-\d+’, ‘’)}}  
with\_items:
- “{{ my\_hotfix\_rpms }}”  
register: r  
args:  
warn: false

I am trying to get a part of RPM name (Epoch) from rpm list in a system. If Epoch is present then it prints the value otherwise prints “0”. Since this package name can have any version , so I am using regex to fetch only the name from the variable.

But I am getting an error telling it is an incomplete Jinja template .Is it because of the ternary operator used? Any idea ?

Regards  
Rahul

---

<div class="post-metadata">

**Author:** ![BIJAY\_PARIDA](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@BIJAY\_PARIDA](https://forum.ansible.com/u/BIJAY_PARIDA)\
**Post date:** [June 25, 2020, 5:37am UTC](https://forum.ansible.com/t/need-help-for-ternary-operator-in-ansible/33243/2 "2020-06-25T05:37:15Z")

</div>

Try escaping the % character.

Thanks  
Bijay
