On 16.11.2017 02:14, DigitalHermit wrote:

On Wednesday, November 15, 2017 at 11:00:08 AM UTC-5, Kai Stian Olstad
wrote:

On Wednesday, 15 November 2017 15.58.47 CET DigitalHermit wrote:
> Is there a cleaner, Ansible way to do this?

Maybe, there's always many ways to tackle a challenge.
Since you haven't shared the specifics it impossible to be specific.


Let me elaborate on my goal:
I have a library of roles. Each of these roles has common tasks across the library. For example, both my install_nginx and install_elk roles have a
common task to create a filesystem.

E.g.:
roles/install_nginx/tasks/create_webdir.yml
roles/install_elk/tasks/create_datadir.yml

To simplify filesystem creation I created an adhoc_fs role and call it from
within the playbook with an include


- name: "Create datadir"
  include_role:
    name: adhoc_fs
    vars:
      adhoc_filesystems:
        { vol_group: 'data_vg', lv_mount: '/mnt/webdata1', lv_name:
'webdata1_lv', lv_size: '40G', owner: apache }
        { vol_group: 'data_vg', lv_mount: '/mnt/webdata2', lv_name:
'webdata2_lv', lv_size: '40G', owner: apache }

This works fine, but the problem is now that my library contains many of
these utility roles. I would prefer to have them all in a single role,
"utility" for example, and call them as needed.  Typical tasks would be
user creation, iptables rules, etc..The point of this is to avoid
copying/pasting from role to role which will ease maintenance.

Know it understand what you are trying to achieve.

Do something like this when is you only option I think, but the problem was all the skipped tasks. In Ansible 2.4 include is depreciated in favor of import_tasks and include_tasks.

The nice thing with include task is that it's dynamic, so you when is check only on the include it self and not on all the task in the included file. import_tasks works like include, when is added to all task before all task is executed.

So with include_task and Ansible 2.4 you will reduce the number of skipped task in the output considerably.


--
Kai Stian Olstad

--
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/c3a350e9f45e6e47975d5ca72580dd0c%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to