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

run_once: true with delegate_to now getting skipped (2.3.0) #23594

Closed
Codelica opened this issue Apr 13, 2017 · 6 comments
Closed

run_once: true with delegate_to now getting skipped (2.3.0) #23594

Codelica opened this issue Apr 13, 2017 · 6 comments
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@Codelica
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

run_once
delegate_to

ANSIBLE VERSION
ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
CONFIGURATION

Nothing notable changed.

OS / ENVIRONMENT

N/A (but using Ubuntu 16.0.4.2 for both)

SUMMARY

I recently updated Ansible to 2.3.0.0 and several tasks that use a run_once: true with delegate_to: 127.0.0.1 are now being skipped. I've included an example below which used to run as long as at least one host was valid (not skipped). Now the play is skipped regardless when run_once: true.

STEPS TO REPRODUCE

Including the task below with one skipped host and one valid host on Ansible 2.3.0.0 results in the task being skipped altogether for me. Changing it to run_once: false allows it to process with first host being skipped and the other triggering it. The issue seems similar to this old (closed) issue -- #9784

"As run_once will always target the first host in the list, if that host is supposed to skip a set of tasks (due to some condition, for instance), it will also skip any run_once tasks even though they may delegate_to other hosts which are willing to run that task."

- name: Clone XXXXXXX locally for v{{ _current_version }}
  git:
    repo: 'git@somehost.somewhere.com:group/project.git'
    dest: '{{ _local_repobase }}/{{ _current_version }}'
    depth: 1
    update: yes
    version: 'v{{ _current_version }}'
  run_once: true
  delegate_to: 127.0.0.1
EXPECTED RESULTS

Task should run once on the local host

ACTUAL RESULTS

Task is skipped.


@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report needs_triage Needs a first human triage before being processed. labels Apr 13, 2017
@sivel
Copy link
Member

sivel commented Apr 13, 2017

I cannot duplicate this. A full output of your playbook run where it fails would be useful.

@sivel sivel added the needs_info This issue requires further information. Please answer any outstanding questions. label Apr 13, 2017
@nitzmahone nitzmahone removed the needs_triage Needs a first human triage before being processed. label Apr 13, 2017
@Codelica
Copy link
Author

Sorry I posted and ran on this one. Should have waited until I was clear of a few things. :)

Anyway, It's entirely possible I don't understand how a "run_once" w/ "delegate_to" should function, but this only popped up after my 2.3.0.0 update. I'm assuming that as long as at least one host is valid (not skipped) that the task will run once and be delegated to the specified host. Just looking at http://docs.ansible.com/ansible/playbooks_delegation.html#run-once

My actual playbook is quite large with lots of inclusions, so I've pared down a simple example.

With the following hosts file:

[test-hosts]
False-Host ansible_host=10.250.0.2 _myVar=false
True-Host ansible_host=10.250.0.3 _myVar=true

and the following playbook:

- hosts: test-hosts

  tasks:

    - name: Clone iot-platform locally for v4.4.5
      git:
        repo: 'git@ourserver.domain.com:group/iot-platform.git'
        dest: '/etc/ansible/test/4.4.5'
        depth: 1
        update: yes
        version: 'v4.4.5'
      run_once: true
      delegate_to: 127.0.0.1
      when: _myVar

The task will be skipped and not cloned locally. Output:

PLAY [test-hosts] *******************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************
ok: [False-Host]
ok: [True-Host]

TASK [Clone iot-platform locally for v4.4.5] ****************************************************************************
skipping: [False-Host]

PLAY RECAP **************************************************************************************************************
False-Host                 : ok=1    changed=0    unreachable=0    failed=0
True-Host                  : ok=1    changed=0    unreachable=0    failed=0

However, if I switch the order of the hosts so that a valid host is first, like this:

[test-hosts]
True-Host ansible_host=10.250.0.3 _myVar=true
False-Host ansible_host=10.250.0.2 _myVar=false

Then the task will execute:

PLAY [test-hosts] *******************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************
ok: [False-Host]
ok: [True-Host]

TASK [Clone iot-platform locally for v4.4.5] ****************************************************************************
changed: [True-Host -> 127.0.0.1]

PLAY RECAP **************************************************************************************************************
False-Host                 : ok=1    changed=0    unreachable=0    failed=0
True-Host                  : ok=2    changed=1    unreachable=0    failed=0

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Apr 19, 2017
@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@alexhexabeam
Copy link

This also affects 2.2.3.0

@bcoca
Copy link
Member

bcoca commented Mar 16, 2018

Possible Misunderstanding

Hi!

Thanks very much for your submission to Ansible. It sincerely means a lot to us.

We believe the ticket you have filed is being somewhat misunderstood, as one thing works a little differently than stated.

The run_once only applies to the FIRST host to hit the loop, if the when condition is False, the task will be skipped. It does NOT run on the first host for which when is True.

In the future, this might be a topic more well suited for the user list, which you can also post here if you'd like some more help with the above.

Thank you once again for this and your interest in Ansible!

@bcoca bcoca closed this as completed Mar 16, 2018
@alexhexabeam
Copy link

alexhexabeam commented Mar 16, 2018

@bcoca I understand that that is the current behavior, but that behavior is not what is intuitively understood, that behavior is not mentioned in the docs, and that behavior is almost certainly not what 99.99999% of people want it to do.

The issue is not that it executes on the first host in the play, but that it DECIDES whether to run at all based on the first node in the play. What is intuitive, and what matches the documentation, is for it to run on the first host in the play, if ANY host in the play matches the when condition.

Even if you disagree with changing it to run if any host matches the when condition, the current behavior is not documented as such. This is still a bug, even if the bug is to just update the documentation to reflect this non-intuitive behavior.

@andygeorge
Copy link

FYI we are able to do the desired behavior using include_tasks::

driver.yml:

- include_tasks: tasks_to_include.yml
  when: conditional_matching_multiple_hosts

tasks_to_include.yml:

- debug: msg="only run on one of the matching hosts"
  run_once: true

Output:

TASK [include_tasks] **********************************************************
Tuesday 14 August 2018  11:30:26 -0500 (0:00:02.175)       0:00:19.835 ********
skipping: [10.X.X.137]
skipping: [10.X.X.222]
skipping: [10.X.X.132]
included: tasks_to_include.yml for 10.X.X.124, 10.X.X.5, 10.X.X.50

TASK [debug] ******************************************************************
Tuesday 14 August 2018  11:30:29 -0500 (0:00:02.343)       0:00:22.178 ********
ok: [10.X.X.124] => {
    "msg": "only run on one of the matching hosts"
}

@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

7 participants