You need to read up on roles.

http://docs.ansible.com/playbooks_roles.html


On Tue, Jan 7, 2014 at 4:38 AM, hafizh <[email protected]> wrote:

> Hi,
>
> I've been playing with Ansible for some time and I'm hitting the wall when
> it comes to re-usability.
> I find that Ansible requires me to duplicate many of my tasks just to
> cater that specific needs.
> Maybe it's the lacking on my side. So, I hope you guys can kindly shed
> some light on this.
>
> I notice that the tasks are very 'strict'. Once we provide an optional
> param, the rest of the lists must provide it too.
>
> Say. I want to create two users:
>     vars:
>       - users:
>         - { name: test1, uid: 1234 }
>         - { name: test2 }
>
> Ideal case would be:
>     tasks:
>         - name: creating user
>           user: name={{ item.name }} uid={{ item.uid }}
>           with_items: users
>
>     ie, I hope Ansible will be smart enough to ignore the optional 'uid'
> for 'test2' but it wont.
>
> The implication is big. Instead of creating a role name 'os_create_user'
> and passing "users" with the neeeded param as the var,
> I need to identify the needed users/param beforehand and create the same
> tasks for each. To put in short, I cannot create them dynamically.
>
> Worse,I cannot share it between different playbooks because of the
> 'strict' requirement.
> So, I ended up creating the same thing for other roles, this time with
> just an extra parameter.
>
> Actually thats some others that I'm having prob with, but I will keep it
> at that first.
> Many thanks in advance for any guidance on this.
>
>  --
> 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].
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Michael DeHaan <[email protected]>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

-- 
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].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to