Hello
Thank you for your answers, parameterized roles is a solution, but it's
actually not as simple as that when you have two environments . After
reading your link I use vars_files for the distinction made by
environment
example site.yml:
- hosts: tomcat1-hosts
user: root
vars_files:
- ['vars/tomcat1_{{ env }}.yml']
pre_tasks:
- debug: msg={{product_dir }}
roles:
- { role: tomcat, tags: tomcat }
- hosts: tomcat2-hosts
user: root
vars_files:
- ['vars/tomcat2_{{ env }}.yml']
pre_tasks:
- debug: msg={{product_dir }}
roles:
- { role: tomcat, tags: tomcat }
My invetory file:
[tomcat1-hosts]
tux1
[tomcat2-hosts]
tux1
[all:children]
tomcat1-hosts
tomcat2-hosts
[all:vars]
env='prod'
Playbook:
PLAY [tomcat1-hosts]
**********************************************************
GATHERING FACTS
***************************************************************
TASK: [debug msg={{product_dir}}]
*********************************************
ok: [tux1] => {
"msg": "/data/produits/tomcat1"
}
PLAY [tomcat2-hosts]
*********************************************************
GATHERING FACTS
***************************************************************
TASK: [debug msg={{product_dir}}]
*********************************************
ok: [tux1] => {
"msg": "/data/produits/tomcat2"
}
So I can deploy to different environments, the same application with
different value for tomcat path, tomcat port. Thanks ansible for that ;)
Le mardi 27 mai 2014 22:11:14 UTC+2, Michael DeHaan a écrit :
>
> "If I want to use tomcat's role for two instances on same host is better
> to use group_vars than the inventory file ? "
>
> group_vars and inventory variables are the same thing expressed two
> different ways.
>
> If you want to use the role twice on the same box, this is a different
> pattern, which are parameterized roles:
>
> Click http://docs.ansible.com/playbooks_roles.html#roles and scroll down
> and it will talk about parameterized roles.
>
> You can pass different parameters to the same role, applied twice, to the
> same server or set of servers.
>
>
>
>
>
> On Mon, May 26, 2014 at 5:02 AM, Sacha Vukovic <[email protected]
> <javascript:>> wrote:
>
>> Thank you for your answer ,
>>
>> If I want to use tomcat's role for two instances on same host is better
>> to use group_vars than the inventory file ?
>>
>>
>>
>> Le vendredi 23 mai 2014 14:18:40 UTC+2, Michael DeHaan a écrit :
>>>
>>> "Sorry I forget to ask you why the variables in group tomcat1 apply
>>> to tomcat2 ?"
>>>
>>> Because the host is in both groups.
>>>
>>> Groups may cover things such as purpose, geographic location, hardware
>>> type, what team owns them, and more.
>>>
>>> The "hosts:" directive merely selects what hosts are going to be
>>> targetted in the given play, and the variables come from all groups, with
>>> subgroups being able to override those of their parents (for instance, a
>>> north_carolina server may specify time.nc.example.com for NTP while a
>>> united_states server might set a default of time.ny.example.com)
>>>
>>>
>>>
>>>
>>> On Thu, May 22, 2014 at 4:21 AM, Sacha Vukovic <[email protected]>
>>> wrote:
>>>
>>>> Hello ,
>>>> Sorry I forget to ask you why the variables in group tomcat1 apply to
>>>> tomcat2 ? whereas I have two groups with different value of variables for
>>>> tomcat's path ?
>>>>
>>>> Le jeudi 22 mai 2014 00:13:54 UTC+2, Michael DeHaan a écrit :
>>>>>
>>>>> What's your question?
>>>>>
>>>>> Thanks.
>>>>>
>>>>>
>>>>> On Wed, May 21, 2014 at 7:28 AM, Sacha Vukovic <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> after reading this post :
>>>>>> https://groups.google.com/forum/#!topic/ansible-project/XbVNoUED2cU
>>>>>> http://docs.ansible.com/intro_inventory.html
>>>>>>
>>>>>> I have a similar question with inventory file,
>>>>>>
>>>>>> I want to provisionning on the same host two tomcat using same role,
>>>>>> but http port, path must be different.
>>>>>>
>>>>>> Example:
>>>>>>
>>>>>> In my inventory file prod.hosts
>>>>>> [tomcat1]
>>>>>> host1
>>>>>>
>>>>>> [tomcat2]
>>>>>> host1
>>>>>>
>>>>>> [tomcat1:vars]
>>>>>> product_dir='/home/produit/tomcat1'
>>>>>> [tomcat2:vars]
>>>>>> product_dir='/home/produit/tomcat2'
>>>>>>
>>>>>> In site.yml
>>>>>> - hosts: tomcat1
>>>>>> user: root
>>>>>> pre_tasks:
>>>>>> - debug: msg={{product_dir}}
>>>>>>
>>>>>> - hosts: tomcat2
>>>>>> user: root
>>>>>> pre_tasks:
>>>>>> - debug: msg={{product_dir}}
>>>>>>
>>>>>> playbook:
>>>>>>
>>>>>> PLAY [tomcat1] ******************************
>>>>>> **********************************
>>>>>>
>>>>>> GATHERING FACTS ******************************
>>>>>> *********************************
>>>>>> ok: [host1]
>>>>>>
>>>>>> TASK: [debug msg={{product_dir}}] ******************************
>>>>>> ***************
>>>>>> ok: [srv-vid-tux48] => {
>>>>>> "msg": "/data/produits/tomcat1"
>>>>>> }
>>>>>>
>>>>>> PLAY [tomcat2] ******************************
>>>>>> **********************************
>>>>>>
>>>>>> GATHERING FACTS ******************************
>>>>>> *********************************
>>>>>> ok: [srv-vid-tux48]
>>>>>>
>>>>>> TASK: [debug msg={{product_dir}}] ******************************
>>>>>> ***************
>>>>>> ok: [srv-vid-tux48] => {
>>>>>> "msg": "/data/produits/tomcat1"
>>>>>> }
>>>>>>
>>>>>>
>>>>>> ansible version 1.6.1
>>>>>>
>>>>>> --
>>>>>> 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 [email protected].
>>>>>> To post to this group, send email to [email protected].
>>>>>>
>>>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>>>> msgid/ansible-project/2535ea07-fabd-4c5a-94f2-2c2fbc8cfe23%
>>>>>> 40googlegroups.com
>>>>>> <https://groups.google.com/d/msgid/ansible-project/2535ea07-fabd-4c5a-94f2-2c2fbc8cfe23%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>> --
>>>> 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 [email protected].
>>>> To post to this group, send email to [email protected].
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/ansible-project/2729242f-410f-49d9-a3ed-
>>>> 0570a980c5f2%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/ansible-project/2729242f-410f-49d9-a3ed-0570a980c5f2%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/f9274998-bf81-4648-b0e2-3353ef2fb0f6%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/f9274998-bf81-4648-b0e2-3353ef2fb0f6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/0d9d2c6c-38a5-4c63-b707-7344272b0e16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.