Skip to content

[WIP] Handle disappearing hosts - #57129

Draft
bcoca wants to merge 4 commits into
ansible:develfrom
bcoca:handle_disappearing_hosts
Draft

bcoca wants to merge 4 commits into
ansible:develfrom
bcoca:handle_disappearing_hosts

Conversation

@bcoca

@bcoca bcoca commented May 29, 2019

Copy link
Copy Markdown
Member

fixes #55669

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

core

@bcoca
bcoca requested a review from jimi-c May 29, 2019 15:26
@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. core_review needs_triage Needs a first human triage before being processed. labels May 29, 2019
Comment thread lib/ansible/executor/play_iterator.py Outdated
@goneri goneri removed the needs_triage Needs a first human triage before being processed. label May 30, 2019
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review and removed core_review needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels May 30, 2019
@nitzmahone

nitzmahone commented May 30, 2019 •

Copy link
Copy Markdown
Member

I built a reproducer for this with an inventory plugin (intending to turn it into a test for this PR), but as-is doesn't fix the issue (piqued my interest as I've often wondered how we'd handle disappearing hosts)...

@bcoca

bcoca commented May 30, 2019

Copy link
Copy Markdown
Member Author

@nitzmahone what is the reproducer? original issue was mostly a confluence of race conditions and i was having a hard time making it happen.

@nitzmahone

Copy link
Copy Markdown
Member

vanish.py

from ansible.plugins.inventory import BaseInventoryPlugin

runcount = 0


class InventoryModule(BaseInventoryPlugin):

    NAME = 'vanish'

    def verify_file(self, path):
        if not path.endswith('.vanish.yml'):
            return False
        return super(InventoryModule, self).verify_file(path)

    def parse(self, inventory, loader, path, cache=True):
        global runcount
        runcount += 1
        group = 'vanishgroup'
        inventory.add_group(group)
        inventory.add_host('h1', group=group)
        print('runcount is %d' % runcount)
        if runcount <= 1:
            inventory.add_host('disappearing_host', group=group)
        inventory.set_variable(group, 'ansible_connection', 'local')

disappearing_host.yml

- hosts: vanishgroup
  gather_facts: no
  tasks:
  - shell: echo yo
    notify: dude
  - meta: refresh_inventory
  - ping:
  handlers:
  - name: dude
    debug: msg=howdy

disappear.vanish.yml

plugin: vanish

ansible-playbook -i disappear.vanish.yml disappearing_host.yml

reproduces it 100% for me

@nitzmahone

Copy link
Copy Markdown
Member

I suspect there are probably a number of other potential hazards for this, but handler exec is a big one. It seems to work as expected without a handler and using the default callback.

@bcoca

bcoca commented May 31, 2019 •

Copy link
Copy Markdown
Member Author

this looks like diff case than the one i was handling: free strat + one of disappearing hosts being slow to return previous result when inventory (run_once) was refreshed.

so we probably have multiple cases that cause errors when a host disappears mid play.

@nitzmahone

Copy link
Copy Markdown
Member

Yeah, I thought about strategy: free too, though I didn't see anything mentioning that in the original issue... Reproducing that case under free should be pretty easy with this- just do a shell: sleep {{ bla }} and have the disappearing host's value of bla be longer than the others.

@nitzmahone nitzmahone closed this May 31, 2019
@nitzmahone nitzmahone reopened this May 31, 2019
@nitzmahone

Copy link
Copy Markdown
Member

I'm also wondering if we should leave "removed" hosts in place and just have an active flag on them that play_iterator et al would just ignore when asking for the next host... Would probably solve a lot of these kinds of problems, since other things like task completion and stats that need to look up hosts would still find them. Otherwise this is probably going to be a long series of race condition whack-a-mole...

@bcoca

bcoca commented May 31, 2019 •

Copy link
Copy Markdown
Member Author

discussed a lot in irc with original author so ticket does not have good reflection of full issue, still unsure that is the case since i could not easily reproduce.

as for ignoring the host, that is kind of what this does, sets state to 'nothing to do' and puts in removed_keys() so it is skipped even if iterator has it in preset objects

need to check why handlers still run, but also need to discuss --force-handlers in this case as well as meta: clear_host_errors

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jun 8, 2019
@bcoca bcoca changed the title Handle disappearing hosts [WIP] Handle disappearing hosts Jun 22, 2019
@ansibot ansibot added the WIP label Jun 22, 2019
@ansibot

This comment has been minimized.

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jun 24, 2019
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 3, 2019
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Jul 19, 2019
Comment thread lib/ansible/executor/task_queue_manager.py Outdated
@ansibot ansibot removed the pre_azp This PR was last tested before migration to Azure Pipelines. label Apr 26, 2021
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 5, 2021
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label May 13, 2021
@bcoca

bcoca commented May 4, 2022

Copy link
Copy Markdown
Member Author

new state 'removed' for host so iterator skips, but still reports on it (remove from hostvars?)

@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jun 26, 2023
@ansibot ansibot added stale_review Updates were made after the last review and the last review is more than 7 days old. has_issue labels Jul 12, 2023
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html and removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. labels Oct 24, 2023
@ansibot ansibot added the stale_pr This PR has not been pushed to for more than one year. label Jan 28, 2025
@bcoca
bcoca marked this pull request as draft June 4, 2025 20:28
@bcoca
bcoca force-pushed the handle_disappearing_hosts branch from 2a5a5e0 to 8dbf996 Compare June 30, 2025 14:30
@ansibot ansibot removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_pr This PR has not been pushed to for more than one year. labels Jun 30, 2025
@webknjaz

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 14, 2025
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Apr 7, 2026
@ansibot ansibot removed the stale_review Updates were made after the last review and the last review is more than 7 days old. label Jun 9, 2026
@ansibot ansibot removed WIP labels Jun 24, 2026
@ansibot ansibot added the stale_pr This PR has not been pushed to for more than one year. label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. has_issue needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_pr This PR has not been pushed to for more than one year.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Randomly receiving 'NoneType' object has no attribute 'name' after inventory refresh

9 participants