Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent role execution. #15409

Closed
pcastellazzi opened this issue Apr 13, 2016 · 4 comments
Closed

Inconsistent role execution. #15409

pcastellazzi opened this issue Apr 13, 2016 · 4 comments
Labels
affects_1.9 This issue/PR affects Ansible v1.9 bug This issue/PR relates to a bug.

Comments

@pcastellazzi
Copy link

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
ansible 1.9.5
  configured module search path = None

ansible 2.0.1.0
  config file = /dev/null
  configured module search path = Default w/o overrides

# from git: d78ba34cf000cc7d5ff57e8f99b679d03d064540
ansible 2.1.0
  config file = /dev/null
  configured module search path = Default w/o overrides
CONFIGURATION
export ANSIBLE_CONFIG=/dev/null
OS / ENVIRONMENT
OSX 10.11.4
python 2.7.11 (homebrew)
SUMMARY

While migrating some playbooks to Ansible 2.0 i found some inconsistencies between different ansible versions, and most importantly in the same version depending of the syntax chosen.
Attached you while find a complete example with variations over the same theme, running the same role multiple times.

STEPS TO REPRODUCE
# the example code is attached
cd example
ansible-playbook -i inventory test1.yml
ansible-playbook -i inventory test2.yml
ansible-playbook -i inventory test3.yml

example.zip

EXPECTED RESULTS

All three playbooks should return the same result.

ACTUAL RESULTS

Each ansible version tested return different results for playbooks that should be equivalent.

@pcastellazzi pcastellazzi changed the title Inconsistent results of role execution. Inconsistent role execution. Apr 13, 2016
@gregsymons
Copy link

gregsymons commented May 9, 2016

Assuming I read the playbooks right, I think the problem, at least for 2.0.1.0, seems to be that variables from previous runs of the role are allowed to bleed into later runs. I have some playbooks that have only be run using 1.9.x that do multiple includes of the same role, and conditionals within the roles are being executed with previous values of the variables used in the condition. I can't speak to what's going on in 2.1; @pcastellazzi was rather vague as to what the actual correct behavior was, only that it's inconsistent between versions.

I would expect that the correct behavior is that any role variables are reset to defaults when the role is executed again, and any variable set for previous role execution that do not have defaults should be deleted. In other words, subsequent runs of a role should occur in a clean, isolated environment without pollution from previous runs. I should be able to reason about how a role will run based solely on the input variables, without any knowledge of the environment that exists around the role.

@pcastellazzi
Copy link
Author

pcastellazzi commented May 9, 2016

Sorry i was not clear enough. Variable bleeding is an issue, yes, but that's not what i meant with inconsistent. i.e.: With ansible 1.9.6 test1.yml run role1 4 times, the same as test3.yml, but test2.yml run it 3 times, even with allow_duplicates: yes.

It's my understanding that each unique role should be executed once, and a unique role include its parameters. A call to {role: rol1, a: 1} it is different from {role: rol1, a: 2}. If that's the case test2.yml is given the correct output, but it should not do it because allow_duplicates: yes was used. An output similar to test1.yml and test3.yml is expected.

When you run this with ansible 2.x role1 is run 3 times on every case, which is again wrong because, for test2.yml it should run 4 times due to allow_duplicates: yes.

# test1.yml
TASK: [role1 | debug msg="[1, 3, 5]"] *****************************************
TASK: [role1 | debug msg="[Undefined, Undefined, Undefined]"] *****************
TASK: [role1 | debug msg="[2, 4, 6]"] *****************************************
TASK: [role1 | debug msg="[Undefined, Undefined, Undefined]"] *****************

# test2.yml
TASK: [role1 | debug msg="[1, 3, 5]"] *****************************************
TASK: [role1 | debug msg="[Undefined, Undefined, Undefined]"] *****************
TASK: [role1 | debug msg="[2, 4, 6]"] *****************************************

# test3.yml
TASK: [role1 | debug msg="[1, 3, 5]"] *****************************************
TASK: [role1 | debug msg="[Undefined, Undefined, Undefined]"] *****************
TASK: [role1 | debug msg="[2, 4, 6]"] *****************************************
TASK: [role1 | debug msg="[Undefined, Undefined, Undefined]"] *****************

@ansibot ansibot added triage affects_1.9 This issue/PR affects Ansible v1.9 labels Sep 7, 2016
@bcoca bcoca removed the triage label Nov 7, 2016
@jainnikhil30
Copy link
Contributor

jainnikhil30 commented Dec 22, 2016

There is one more inconsistency noticed

Following scenario

roles:

  • role1
  • role1

With this role 1 gets executed twice, without setting allow_duplicates:yes

But for the following scenario

roles:

  • role1
  • role2
  • role1

Second instance to role1 only gets executed if allow_duplicates: yes is set. I have tried this on ansible 2.1, 2.2 and devel 2.3 they all have same behaviour.

jimi-c added a commit that referenced this issue Dec 28, 2016
When the same role is listed consecutively in a play, the previous role
completion detection failed to mark it as complete as it only checked to
see if the role changed.

This patch addresses that by also keeping track of which task in the role
we are on, so that even if the same role is encountered during later passes
the task number will be less than or equal to the last noted task position.

Related to #15409
jimi-c added a commit that referenced this issue Jan 3, 2017
When the same role is listed consecutively in a play, the previous role
completion detection failed to mark it as complete as it only checked to
see if the role changed.

This patch addresses that by also keeping track of which task in the role
we are on, so that even if the same role is encountered during later passes
the task number will be less than or equal to the last noted task position.

Related to #15409
jimi-c added a commit that referenced this issue Jan 3, 2017
When the same role is listed consecutively in a play, the previous role
completion detection failed to mark it as complete as it only checked to
see if the role changed.

This patch addresses that by also keeping track of which task in the role
we are on, so that even if the same role is encountered during later passes
the task number will be less than or equal to the last noted task position.

Related to #15409
jimi-c added a commit that referenced this issue Jan 3, 2017
When the same role is listed consecutively in a play, the previous role
completion detection failed to mark it as complete as it only checked to
see if the role changed.

This patch addresses that by also keeping track of which task in the role
we are on, so that even if the same role is encountered during later passes
the task number will be less than or equal to the last noted task position.

Related to #15409

(cherry picked from commit fed079e)
jimi-c added a commit that referenced this issue Jan 3, 2017
When the same role is listed consecutively in a play, the previous role
completion detection failed to mark it as complete as it only checked to
see if the role changed.

This patch addresses that by also keeping track of which task in the role
we are on, so that even if the same role is encountered during later passes
the task number will be less than or equal to the last noted task position.

Related to #15409
@jimi-c
Copy link
Member

jimi-c commented Jan 3, 2017

Closing This Ticket

Hi!

We believe the above commit should resolve this problem for you. This will also be included in the next release.

Do note however, that roles instantiated with different parameters are not considered duplicates, so for most of the examples in the original run you will see multiple invocations of the role.

If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!

@jimi-c jimi-c closed this as completed Jan 3, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_1.9 This issue/PR affects Ansible v1.9 bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

7 participants