Hi,

You can use parameterized roles …
I use the following to create several DB using one role (roughly):

roles/create_db/tasks/main.yml:

- name: create {{ db_name }}
  mysql_db: name={{ db_name }} encoding=utf8 login_user=root state=present 
login_password={{ mysql_root_password }}

then it is called as follow in the playbook:

- hosts: db_server
  roles:
      - { role: create_db, db_name: DB_1 }
      - { role: create_db, db_name: DB_2 }
      - { role: create_db, db_name: DB_3 }


Typically, for an apache vhost configuration, you could pass the value of 
“servername" and “documentroot” to the webserver role like this

role:
        - { role: webservers, servername: www.site1.com, documentroot: 
/var/www/site1 }
        - { role: webservers, servername: www.siteB.com, documentroot: 
/var/www2/siteB }

- note 1:
you should be using {{ my_var }} instead of $my_var

-note 2:
you are mentioning role dependencies, which is meant to configure… dependencies 
between roles (ie the role webservers requires the role common) and I am not 
sure that it is related to you question 
http://www.ansibleworks.com/docs/playbooks_roles.html#role-dependencies 

HTH

Fred

On Nov 28, 2013, at 13:37 , Shih Oon Liong <shihoon.li...@invokelabs.com> wrote:

> Hi,
> 
> I am kinda confused on what is the right syntax to try out this. Running a 
> role multiple times in a single playbok but a different var_files each time.
> 
> I have a web server role for a LAMP stack that will also install the Apache 
> vhost site. My idea was that I can run this role on the same server if I was 
> installing multiple sites - Ansible would just skip the software 
> installations but just install the vhost configs.
> 
> This works fine if I run the playbook multiple times manually. What I want to 
> do is to do this multiple times in one single playbook. My assumption is that 
> I should be using Role Dependencies (amirite?).
> 
> My current playbook *roughly*
> 
> ---
> # Deployment for web servers
> # 
> - hosts: $hosts
>   user: $user
>   sudo: true
>   name: Install Apache and PHP.
>   vars_files:
>     - $config_path
>     
>   roles:
>     - common
>     - webservers
> 
> 
> As you can see, I heavily use vars_files since I find configs to be in a 
> separate file much easier to manage. 
> 
> What I am confused is how can I use role dependencies but load up a different 
> var_files each time round? The example in the documentation seems to imply 
> just individual variable replacements but my webservers role has several 
> variables that need to be set for a site install which will make it unwieldy.
> 
> Any help is much appreciated. Thanks!
> 
> 
> 
> 
> Invoke Labs – A business building company that equips new digital ventures 
> for long term success.
> Twitter | Facebook | LinkedIn | Blog | 
> 
> Check out the latest products from Invoke Labs: Pendo Rent and myBestHelper.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to ansible-project+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to