haxorof/ansible-role-docker-ce

Usage of `tags: ["always"]` messes up with using tags in playbook

sgautrin opened this issue · 3 comments

  • Ansible: 2.9.1
  • Role: 2.6.2 (commit 55c7487)

Steps to Reproduce

  1. create a simple playbook using two roles each with their tag, e.g.

    - hosts: localhost
      roles:
        - role: haxorof.docker_ce
          tags: do_docker
    
        - role: other_role
          tags: do_other_role
    
  2. try to run the playbook activating only the tag for the second role, e.g. ansible-playbook -t do_other_role test_play.yml

Expected Behavior

The role haxorof.docker_ce should be completely skipped.

Actual Behavior

  1. The tasks in the role tagged always are executed
  2. If there is no explicit fact gathering prior to that in the playbook, then those tasks fail with 'ansible_distribution_major_version' is undefined

This means that in the example above, if we only want the tasks from other_role to be executed, we need to exclude do_docker instead of including only do_other_role, which becomes problematic when there is more than just two tags in the playbook and we want to run only one: we then need to both select and exclude tags, and if all roles were to do the same, we would need to exclude a long list of tags instead of simply selecting one.

Suggestion

One solution could be to list all the tags (install, configure, postinstall) instead of always, though that will mean those tasks would not execute if one of those tags is skipped (e.g. doing --skip-tags configure instead of -t install).

Additionally, using more specific tag names (e.g. docker_install, docker_configure, docker_postinstall) would probably be a good idea to reduce the risks of collision with tags used by other roles or playbooks using them.

References

Thanks for reporting this. Will have a look at it.

Happy New Year!

@sgautrin I did a quick fix on the master and removed the always tag. Just tested quickly to list which tasks which was executed but not run it. Please let me know if this fix work for you.

Note! I added tags as you suggested but will not remove the existing that which are replaced because it might break for people using those tags. Will write a deprecation notice and remove them later release.

Please let me know if this fix work for you.

It does, thank you.