# Adding if statement inside a task

**URL:** <https://forum.ansible.com/t/adding-if-statement-inside-a-task/36300>\
**Category:** Ansible Project\
**Created:** [February 7, 2022, 2:29pm UTC](https://forum.ansible.com/t/adding-if-statement-inside-a-task/36300 "2022-02-07T14:29:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dudu.c](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@dudu.c](https://forum.ansible.com/u/dudu.c)\
**Post date:** [February 7, 2022, 2:29pm UTC](https://forum.ansible.com/t/adding-if-statement-inside-a-task/36300/1 "2022-02-07T14:29:37Z")

</div>

Hi  
I have the following playbook.  
In the environment.yml file I have a parameter “tls=true”

In the below task , In tghe URL I would put **https** if tls=true and **http** if false.

- hosts: manager  
vars\_files:

- ./environment.yml  
tasks:

- name: test - check connectivity to API  
get\_url:  
url: http://{{ server.hostname }}.{{ domain }}:9999/api//{{ cluster\_name }}  
dest: /tmp/  
mode: 0777  
force: yes  
url\_username: “{{ username }}”  
url\_password: “{{ password }}”  
validate\_certs: no  
register: msg  
ignore\_errors: true

Thanks

---

<div class="post-metadata">

**Author:** ![Rilindo\_Foster1](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Rilindo\_Foster1](https://forum.ansible.com/u/Rilindo_Foster1)\
**Post date:** [February 7, 2022, 2:36pm UTC](https://forum.ansible.com/t/adding-if-statement-inside-a-task/36300/2 "2022-02-07T14:36:27Z")

</div>

Hi there!

What was the problem that you are trying to solve? I don’t see an actual question that we can answer.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [February 7, 2022, 2:43pm UTC](https://forum.ansible.com/t/adding-if-statement-inside-a-task/36300/3 "2022-02-07T14:43:50Z")

</div>

Try:

url: “http{{ ‘s’ if tls else ‘’ }}://{{ server.hostname }}.{{ domain }}:9999/api//{{ cluster\_name }}”
