# Defining variables in tasks

**URL:** <https://forum.ansible.com/t/defining-variables-in-tasks/17165>\
**Category:** Ansible Project\
**Created:** [December 31, 2014, 11:10am UTC](https://forum.ansible.com/t/defining-variables-in-tasks/17165 "2014-12-31T11:10:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dirk\_Roder](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@Dirk\_Roder](https://forum.ansible.com/u/Dirk_Roder)\
**Post date:** [December 31, 2014, 11:10am UTC](https://forum.ansible.com/t/defining-variables-in-tasks/17165/1 "2014-12-31T11:10:45Z")

</div>

Hello together,  
I’m trying with ansible since 2 days and I’m really happy with it after getting behind the idea of playbooks.

Currently I’m stuck with a situation and I’m not sure if this is a conceptual mistake.

I have defined 3 roles currently:

- basicConfig (Containing network config, SSHd configuration, NTP and so on. Working fine).
- mailServices (Containing postfix with tools and configuration. Still to write)
- webServices (Containing installation of Apache, PHP and MySQL, including all applications like Dokuwiki, Roundcube Webmail and TinyTinyRSS).

For webservices I have a question. This is my directory structure:  
.  
├── group\_vars  
│ └── testcrows  
├── hosts  
├── host\_vars  
├── roles  
│ └── webServices  
│ ├── files  
│ ├── handlers  
│ │ └── main.yml  
│ ├── tasks  
│ │ ├── dokuwiki.yml  
│ │ ├── main.yml  
│ │ ├── ttrss.yml  
│ │ └── webmail.yml  
│ ├── templates  
│ │ └── apacheSites  
│ │ ├── template.j2  
│ └── vars  
│ └── main.yml  
└── webServices.yml

I’m running webServices.yml as playbook which is then running main.yml (installation of Apache, MySQL, …) and then including dokuwiki.yml, ttrss.yml and webmail.yml.  
In general the last 3 ones are doing closely the same (Downloading Installer, unziping, moving to dest directory, creating database and writing apache conf (based on template.j2).  
I would like to set parameters to each of the 3 files, which are used in the template so for example:

`  
ServerName {{ app\_vHost }}.{{ systemDomain }}

`  
This would allow me to have only one template for the easy applications, but having each on their own vHost definition. So avoiding redundancy.

So Question No. 1:  
Is this an appropriate way to define the directory structure? If yes, how do I assign variables within the taks file? If I assign a vars Part, I do get syntax errors, so doesn’t seem to belong there?!

Question 2:  
I would like to include these tasks only if the destination path is not yet there. I managed to write everything in static, but how can I use this then on the include part. So currently my webServices.yml is this:

`
