Hi,

I don’t know what you’re trying to achieve exactly … but assuming that all your 
vhosts have the same configuration file structure, you could use a template and 
to something like below:

roles/
        webservers/
                tasks/main.yml
                vars/main.yml
                templates/vhost.conf.j2

playbook:
***********
— 
hosts: my_servers
roles:
        - { role: webservers, vhost_name: www.sitea.com, vhost_root: 
/var/www/sitea }
        - { role: webservers, vhost_name: www.siteb.com, vhost_root: 
/var/www/siteb }

task/main.yml:
****************
—
- name: copy vhost config
  template: dest=/etc/httpd/conf.d/{{ vhost_name }}.conf src=vhost.conf.j2
  sudo: yes

templates/vhost.conf.j2:
****************
<VirtualHost {{ ansible_eth0.ipv4.address }}>
DocumentRoot {{ vhost_root }}
ServerName {{ vhost_name }}
</VirtualHost>

cheers,

fred

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

> I didn't realized about the parameterized roles. I'll give that go! But that 
> also cleared up on what role dependencies was suppose to be for.
> 
> What I am try to do though is to load up a different config file instead so 
> that instead of me trying to do 
> 
> var_files
>    - config_file
> role:
>       - { role: webservers, servername: www.site1.com, documentroot: 
> /var/www/site1 }
>       - { role: webservers, servername: www.siteB.com, documentroot: 
> /var/www2/siteB }
> 
> I can do something like 
> 
> var_files
>    - config_file
> role:
>       - { role: webservers, [ Config file 1] }
>       - { role: webservers, [ Config file 2] }
> 
> Though I guess maybe the var_files should be in the roles itself perhaps? I 
> could try to make my role take in either individual vars or if a var_files is 
> defined, to use that instead?
> 
> On Thursday, November 28, 2013 5:09:06 AM UTC-8, Fred Badel wrote:
> 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 <shihoo...@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-proje...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 
> 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