robertdebock / ansible-role-users

The purpose of this role is to add users and groups on your system.
https://robertdebock.nl/
Apache License 2.0
42 stars 27 forks source link

Use task (filename) prefix for the task name #27

Closed dzintars closed 1 year ago

dzintars commented 1 year ago

Proposed feature

Use task name prefix like - name: lsp | Install Cargo crates and enable_list: - name[prefix] in Ansible Lint.

Rationale

Because this role is organized into multiple files and can be imported in larger playbook it is important to provide observability for the users. It is common to rely on --list-tasks to quickly identify executable tasks and their locations in the roles.

$ molecule --base-config .config/molecule/config.yml converge -s dev -- --limit workstations --tags nvim --list-tasks
.......

 play #3 (workstations): PPE     TAGS: [ppe]
    tasks:
      namespace.generic.nodejs : prepare | Ensure Nodejs directory exists    TAGS: [deps, nodejs.prepare, nodejs.setup, nvim, ppe]
      namespace.generic.nodejs : prepare | Install unzip package    TAGS: [deps, nodejs.prepare, nodejs.setup, nvim, ppe]
      namespace.generic.nodejs : install | Download NodeJS release source   TAGS: [deps, nodejs.install, nodejs.setup, nvim, ppe]
      namespace.generic.nodejs : environment | Setup NodeJS environment     TAGS: [deps, nodejs.environment, nodejs.setup, nvim, ppe]
      namespace.generic.yarn : install | Install Yarn     TAGS: [deps, install, nvim, ppe, yarn, yarn.install]
      namespace.generic.yarn : config | Add environment     TAGS: [deps, nvim, ppe, yarn, yarn.config]
      namespace.generic.nvim : prepare | Install Neovim build prerequisites     TAGS: [deps, nvim, nvim.prepare, ppe]

As you can see, user is able easily identify the source of particular task.

Same goes to spot the source of failing tasks.

robertdebock commented 1 year ago

Hi,

If I understand you correctly, you'd like to have all tasks have a prefix. Should that prefix be selected from:

Or is that prefix free-format?

I don't see why a prefix solves the observability issue, if unique name:s are used, that should help the User right?

And another issue; ansible-lint would like all named tasks to start with a capital.

I'm curious to your way of thinking, please let me know.

dzintars commented 1 year ago

First of all, this is only my opinionated suggestion. 😃

By the rules of ansible-lint, prefix should match the file name in which the task is defined. Capitalized named tasks rule applies to - name: filename | This is the capitalized task name part. Not to the prefix itself.

In your case prefixes would be:

enable_list: - name[prefix] should be explicitly enabled in ansible-lint config. There is some random documentation i just found about it Good Practices for Ansible - GPA

All of this does not matter much if you are working just with one or few roles. But when you have entire playbooks which consumes 20-50-100 roles, this becomes quite important. Because you have such generic role, i see it being used in larger playbooks and thus IMHO task naming becomes important.

I would suggest to try it locally and to play with --list-tasks on entire playbook to see the effect.

robertdebock commented 1 year ago

This one if fixes, actually on all my roles.

And; indeed it's useful! Thanks for then hint. 👊🏻