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

Tasks run multiple times if host is included in hosts more than once #5631

Closed
nikut opened this issue Jan 15, 2014 · 0 comments
Closed

Tasks run multiple times if host is included in hosts more than once #5631

nikut opened this issue Jan 15, 2014 · 0 comments
Labels
bug This issue/PR relates to a bug.

Comments

@nikut
Copy link
Contributor

nikut commented Jan 15, 2014

Hi,

I have encountered an issue where tasks run multiple times on hosts that belong to several groups included in the play hosts line with the OR operator (ie. "hosts: group1:group2") when one of the groups is generated at run time using add_host.

This happens on both Ansible 1.4.4 and current devel.

Please see the test case below:

inventory/hosts

[testgroup]
foo

[testgroup2]
foo

test.yml

--- 
- name: Add test host
  hosts: localhost
  connection: local
  gather_facts: no

  tasks:
    - name: Add host to temporary group
      local_action: add_host hostname=foo groupname=tempgroup

# Run a task against two groups, both defined in inventory (works correctly)
- name: Test 1
  hosts: testgroup:testgroup2
  gather_facts: no
  tasks:
    - name: Check host
      local_action: command /bin/true

# Run a task agains two groups, one defined in inventory and another at run time (works incorrectly)
- name: Test 2
  hosts: testgroup:tempgroup
  gather_facts: no
  tasks:
    - name: Check host
      local_action: command /bin/true

Expected output (Test 1 and Test 2 are exactly the same):

PLAY [Add test host] ********************************************************** 

TASK: [Add host to temporary group] ******************************************* 
ok: [localhost]

PLAY [Test 1] ***************************************************************** 

TASK: [Check host] ************************************************************ 
changed: [foo]

PLAY [Test 2] ***************************************************************** 

TASK: [Check host] ************************************************************ 
changed: [foo]

Actual output (Test 2 task runs twice):

PLAY [Add test host] ********************************************************** 

TASK: [Add host to temporary group] ******************************************* 
ok: [localhost]

PLAY [Test 1] ***************************************************************** 

TASK: [Check host] ************************************************************ 
changed: [foo]

PLAY [Test 2] ***************************************************************** 

TASK: [Check host] ************************************************************ 
changed: [foo]
changed: [foo]

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants