# Checking for multiple conditions using “when” on single task in ansible

**URL:** <https://forum.ansible.com/t/checking-for-multiple-conditions-using-when-on-single-task-in-ansible/19828>\
**Category:** Ansible Project\
**Created:** [November 22, 2015, 4:48pm UTC](https://forum.ansible.com/t/checking-for-multiple-conditions-using-when-on-single-task-in-ansible/19828 "2015-11-22T16:48:47Z")\
**Posts on this page:** 1\
**Page:** 1

<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:** [November 22, 2015, 4:48pm UTC](https://forum.ansible.com/t/checking-for-multiple-conditions-using-when-on-single-task-in-ansible/19828/1 "2015-11-22T16:48:47Z")

</div>

I want to evaluate multiple condition in ansible using when, here is my playbook:

```auto
- name: Check that the SSH Key exists
   local_action:
     module: stat
     path: "/home/{{ login_user.stdout }}/{{ ssh_key_location }}"
   register: sshkey_result

 - name: Generating a new SSH key for the current user it's not exists already
   local_action:
      module: user
      name: "{{ login_user.stdout }}"
      generate_ssh_key: yes 
      ssh_key_bits: 2048
   when: sshkey_result.rc == 1 and ( github_username is undefined or github_username |lower == 'none' )

```

here is my var file for reference:

```auto
---
vpc_region: eu-west-1
key_name: my_github_key
ssh_key_location: .ssh/id_rsa.pub

```

When I try to execute this playbook, I am getting this error:

```auto
TASK: [test | Check that the SSH Key exists] **********************************
ok: [localhost -> 127.0.0.1]

 TASK: [test | Generating a new SSH key for the current user it's not exists already] ***
 fatal: [localhost] => error while evaluating conditional: sshkey_result.rc == 1 and ( github_username is undefined or github_username |lower == 'none' )

        FATAL: all hosts have already failed -- aborting

```

Can somebody point me out that how we can use multiple conditions with ansible on single task.

Thanks
