Dependency related issue

I have 2 roles: longstash and elasticsearch.
The logstash role is dependant on elasticsearch.
In each role, all tasks are flagged with the name of the role.
In addition, in elasticsearch role I have tasks that open ports in iptables - which are signaling a handler that restarts the iptables service if they make a change.
Now, I run an ansible-playbook that has these roles, with a --flags "elasticsearch" to install it first alone. What happens, is that the elasticsearch tasks all run, and then they all run again becaus ansible's mechanism figured out that the logstash role depends on elasticsearch and thus ansible collected these tasks twice.
But it gets worst - because the second run does not change the iptables setting from what happened after the first run, then ansible thinks there was no change, and thus does not trigger the handler that would have supposed to restart iptables.

The moment I remove the elasticsearch-role from the dependancy-list of logstash, everything works correctly.

I’m having some difficulty understanding your question.

(A) Ansible does not have anything called --flags, did you mean tags?

(B) Are you reporting a problem where tags on one role don’t get applied to dependent roles, or something else?

Well, obviously I meant --tags… Sorry about that.

Yes - I am reporting a problem.
I tried to explain it the best I could in a short description - here is the long version:

It happens when you combine the use of role-dependencies, task-tagging, and running of “ansible-playbook” on a playbook that includes both roles, with the “–tags” parameter to filter only tasks of a specific role.
What happens is that due to some other role that is set to be dependant on that first one, ansible duplicates the running of the task-sequence in the first role.

In other words, let’s say you have a playbook that has 2 roles: “A” and “B”.
Within each role, you “tag” all of the tasks with the name of the role - for example:

In “…/roles/A//tasks/main.yml”:

Please make sure there is a ticket for this in github

github.com/ansible/ansible

see “reporting a bug” in https://github.com/ansible/ansible/blob/devel/CONTRIBUTING.md