# Ternary module not working for default value

**URL:** <https://forum.ansible.com/t/ternary-module-not-working-for-default-value/28701>\
**Category:** Ansible Project\
**Created:** [October 1, 2018, 6:46pm UTC](https://forum.ansible.com/t/ternary-module-not-working-for-default-value/28701 "2018-10-01T18:46:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [October 1, 2018, 6:46pm UTC](https://forum.ansible.com/t/ternary-module-not-working-for-default-value/28701/1 "2018-10-01T18:46:00Z")

</div>

##### SUMMARY  
When I want to use skip the task if the extra-vars parameter is passed like default in playbook from the role

##### ISSUE TYPE  
- Bug Report

##### COMPONENT NAME  
ansible-core

##### ANSIBLE VERSION

```auto
ansible 2.6.1
  config file = /etc/ansible/playbooks/example/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

```

##### CONFIGURATION

```auto
ansible 2.6.1
  config file = /etc/ansible/playbooks/example/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

```

##### OS / ENVIRONMENT  
CentOS Linux release 7.5.1804 (Core)

##### STEPS TO REPRODUCE

```yaml
roles/common/tasks/main.yml
---
- name: Reloading Service on {{ansible_hostname}}
  service:
    name: "{{ item }}"
    state: reloaded
  with_items: "{{ (servicename is defined) | ternary((servicename|default('')).split(','),[]) }}"

- name: checking the service status {{ansible_hostname}}
  service:
    name: "{{ item }}"
    state: started
  with_items: "{{ (servicename is defined) | ternary((servicename|default('')).split(','),[]) }}"

```

```YAML
playbook.yaml
- name: checking service is skipped by default
  hosts: {{host}}
  vars_files:
    - /etc/ansible/inventories/group_vars/common.yaml
  serial: 1
  roles:
    - common

```

#####ansible command  
ansible-playbook -vv --vault-id sre@/opt/sre -i /etc/ansible/inventories/funccphosts test.yml --extra-vars "host=node1,node2 servicename="

##### EXPECTED RESULTS  
I want to just skip the task of service if I am not passing any service name variable

##### ACTUAL RESULTS

```auto
TASK [common_role_ : Reloading Service on node1] ****************************
task path: /etc/ansible/roles/common_role_cow/tasks/main.yml:17
Thursday 27 September 2018 13:06:27 +0000 (0:00:00.529) 0:00:09.391 ****
fatal: [node1]: FAILED! =>
  msg: '''list object'' has no attribute ''split'''

```

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [October 2, 2018, 2:46am UTC](https://forum.ansible.com/t/ternary-module-not-working-for-default-value/28701/2 "2018-10-02T02:46:20Z")

</div>

Is there anyone can help on this

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [October 2, 2018, 3:48am UTC](https://forum.ansible.com/t/ternary-module-not-working-for-default-value/28701/3 "2018-10-02T03:48:11Z")

</div>

what is exactly the issue? you need to provide more information.

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [October 2, 2018, 4:23am UTC](https://forum.ansible.com/t/ternary-module-not-working-for-default-value/28701/4 "2018-10-02T04:23:12Z")

</div>

When I am passing servicename parameter as the task has to be skipped. But it is giving error

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [October 2, 2018, 4:24am UTC](https://forum.ansible.com/t/ternary-module-not-working-for-default-value/28701/5 "2018-10-02T04:24:03Z")

</div>

If you see my playbook and ansible-playbook its work fine for passing parameter but if I pass no value the task has to be skipped

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [October 2, 2018, 2:13pm UTC](https://forum.ansible.com/t/ternary-module-not-working-for-default-value/28701/6 "2018-10-02T14:13:17Z")

</div>

Guies is there any update or you need any information.

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [October 4, 2018, 8:42am UTC](https://forum.ansible.com/t/ternary-module-not-working-for-default-value/28701/7 "2018-10-04T08:42:41Z")

</div>

Hello Ansible Team,

Is there any update on issue.

This is important.
