Hi Dmitry,

I would suggest you to use my approach bellow:

    # Load a variable file based on the OS type, or a default if not found.
    - include_vars: "{{ item }}"
      with_first_found:
        - "{{ ansible_distribution }}.yml"
        - "{{ ansible_os_family }}.yml"
        - "default.yml"
    - action: '{{ pkg_mgr }} name={{ item }} state=latest'
      with_items: packages

  # Ubuntu.yml
  pkg_mgr: apt
  packages:
    - bash
    - screen
    - curl

Here is a gist: https://gist.github.com/hostmaster/db37c8e6c2a43997a224

-- Best, Igor

On Thu, Oct 2, 2014 at 1:20 PM, Dmitry Sukhodoyev <[email protected]> wrote:
> Hello. Now I do sime things from roles/host_generic/tasks/main.yaml:
>
> - include: ../../includes_common/pkg_from_repo.yaml
>   vars:
>    name: 'bash'
> - include: ../../includes_common/pkg_from_repo.yaml
>   vars:
>    name: 'bash-completion'
> - include: ../../includes_common/pkg_from_repo.yaml
>   vars:
>    name: "{{generic_vim_pkg_name}}"
> - include: ../../includes_common/pkg_from_repo.yaml
>   vars:
>    name: 'screen'
> - include: ../../includes_common/pkg_from_repo.yaml
>   vars:
>    name: 'logrotate'
> - include: ../../includes_common/pkg_from_repo.yaml
>   vars:
>    name: 'sudo'
> - include: ../../includes_common/pkg_from_repo.yaml
>   vars:
>    name: 'wget'
> - include: ../../includes_common/pkg_from_repo.yaml
>   vars:
>    name: 'rsync'
> - include: ../../includes_common/pkg_from_repo.yaml
>   vars:
>    name: 'munin-node'
> I guess it's a long way. Is it possible to reuse some code from roles
> shorter? Using role from other role will be perfect solution, but I unable
> to found way how.
>
> roles/includes_common/pkg_from_repo.yaml is installer for all possible
> operation systems is I replace includes in previous file to modules command,
> this file will bigger at 3-4 times.
> ---
> - name: install RedHat package
>   yum: name="{{name}}" state=present
>   when: ansible_os_family == 'RedHat'
> - name: install RedHat package
>   apt: name="{{name}}" state=present
>   when: ansible_os_family == 'Debian'
> - name: install RedHat package
>   openbsd_pkg: name="{{name}}" state=present
>   when: ansible_system == 'OpenBSD'
> - name: install FreeBSD package
>   pkgng: name="{{name}}" state=present
>   when: ansible_system == 'FreeBSD'
>
> Also, it is incorrect decision to move pkg_from_repo.yaml to another
> directory like roles/host_generic/tasks, because from other roles it will be
> called as "include: ../../host_genetic/tasks/pkg_from_files.yaml" - much
> more text in call.
>
> --
> 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/ab61eb2a-8a0e-4652-8d9a-0bf61cb73c9f%40googlegroups.com.
> 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/CAGuanspvNrwmLVCR1eVZ8B%3DJcKOyuLdcJLrxE%3DX87roAMHkvQg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to