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

Errors in block never trigger rescue or always in plays included from a handler #40130

Closed
mileshampson opened this issue May 15, 2018 · 3 comments
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@mileshampson
Copy link

mileshampson commented May 15, 2018

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Core

ANSIBLE VERSION
ansible 2.5.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ops/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Sep 18 2017, 00:00:00) [GCC 4.8.4]
CONFIGURATION

ANSIBLE_PIPELINING(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = -q -o ControlPersist=15m -o ControlMaster=auto -o PreferredAuthentications=publickey -o GSSAPIAuthentication=no
ANSIBLE_SSH_CONTROL_PATH(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = ~/.ssh/mux-%%r@%%h:%%p
ANSIBLE_SSH_RETRIES(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = 10
CACHE_PLUGIN(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = /tmp
CACHE_PLUGIN_TIMEOUT(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = 2592000
COMMAND_WARNINGS(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = False
DEFAULT_FORKS(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = 500
DEFAULT_SCP_IF_SSH(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = True
DEPRECATION_WARNINGS(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = False
RETRY_FILES_ENABLED(/home/ops/projects/ng/miles_ops/ansible/ansible.cfg) = False

OS / ENVIRONMENT

Ubuntu 14.04.5 LTS

SUMMARY

In plays included from a handler, rescue and always block sections are never called. This is important because this appears to be the only workaround (as described in the first comment here: #14270) for ansible not having any way to run a task when a handler fails.

STEPS TO REPRODUCE
upgrade
|-handlers
  main.yml
  - name: upgrade task
    include: upgrade.yml
|-tasks
  main.yml
  - name: Update configuration 1
    template: src=conf.j2 dest={{ conf_dir }}/conf.conf
    notify: upgrade task
  - name: Update configuration 2
    template: src=conf2.j2 dest={{ conf_dir }}/conf2.conf
    notify: upgrade task

  upgrade.yml
  - block:
    - debug: msg="Starting upgrade"
    - name: Simulate failure of first of many upgrade tasks
      command: /bin/false
    rescue:
    - debug: msg="Upgrade failed, rolling back now"
    always:
    - debug: msg="Upgrade finished"
EXPECTED RESULTS

The output of the block should be the same as if it were run in main.yml, i.e.

TASK [upgrade : debug] ***********************************************************************************************************************************************************************************************
ok: [myhost] => {
    "msg": "Starting upgrade"
}

TASK [upgrade : Simulate failure of first of many upgrade tasks] *****************************************************************************************************************************************************
fatal: [myhost]: FAILED! => {"changed": true, "cmd": ["/bin/false"], "delta": "0:00:00.000907", "end": "2018-05-15 06:21:32.541031", "msg": "non-zero return code", "rc": 1, "start": "2018-05-15 06:21:32.540124", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

TASK [upgrade : debug] ***********************************************************************************************************************************************************************************************
ok: [myhost] => {
    "msg": "Upgrade failed, rolling back now"
}

TASK [upgrade : debug] ***********************************************************************************************************************************************************************************************
ok: [myhost] => {
    "msg": "Upgrade finished"
}
ACTUAL RESULTS

Only the tasks in block: are run. At level -vvvv this looks like:

RUNNING HANDLER [upgrade : debug] ************************************************************************************************************************************************************************************
ok: [myhost] => {
    "msg": "Starting upgrade"
}

RUNNING HANDLER [upgrade : Simulate failure of first of many upgrade tasks] ******************************************************************************************************************************************
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/commands/command.py
<myhost> ESTABLISH SSH CONNECTION FOR USER: None
<myhost> SSH: EXEC ssh -vvv -q -o ControlPersist=15m -o ControlMaster=auto -o PreferredAuthentications=publickey -o GSSAPIAuthentication=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath=~/.ssh/mux-%r@%h:%p' dev03.adn.bitshift.technology '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-jqstohktuqdpwwjxvukiwgpaxelkwueq; /usr/bin/python'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<myhost> (1, '\n{"changed": true, "end": "2018-05-15 06:30:34.421465", "stdout": "", "cmd": ["/bin/false"], "failed": true, "delta": "0:00:00.000910", "stderr": "", "rc": 1, "invocation": {"module_args": {"warn": false, "executable": null, "_uses_shell": false, "_raw_params": "/bin/false", "removes": null, "creates": null, "chdir": null, "stdin": null}}, "start": "2018-05-15 06:30:34.420555", "msg": "non-zero return code"}\n', '')
fatal: [myhost]: FAILED! => {
    "changed": true, 
    "cmd": [
        "/bin/false"
    ], 
    "delta": "0:00:00.000910", 
    "end": "2018-05-15 06:30:34.421465", 
    "invocation": {
        "module_args": {
            "_raw_params": "/bin/false", 
            "_uses_shell": false, 
            "chdir": null, 
            "creates": null, 
            "executable": null, 
            "removes": null, 
            "stdin": null, 
            "warn": false
        }
    }, 
    "msg": "non-zero return code", 
    "rc": 1, 
    "start": "2018-05-15 06:30:34.420555", 
    "stderr": "", 
    "stderr_lines": [], 
    "stdout": "", 
    "stdout_lines": []
}
META: ran handlers
@mileshampson mileshampson changed the title Errors in block never trigger rescue or always in plays included from a handler Errors in block never trigger rescue or always in plays included from a handler May 15, 2018
@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels May 15, 2018
@webknjaz
Copy link
Member

-label needs_triage

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label May 15, 2018
@fractalic
Copy link

Also interested in this

@mkrizek
Copy link
Contributor

mkrizek commented Sep 6, 2018

Duplicate of #14270

@mkrizek mkrizek marked this as a duplicate of #14270 Sep 6, 2018
@mkrizek mkrizek closed this as completed Sep 6, 2018
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 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

5 participants