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

Ansible fails when until condition is true on last retry. #15697

Closed
kuboj opened this issue May 3, 2016 · 1 comment
Closed

Ansible fails when until condition is true on last retry. #15697

kuboj opened this issue May 3, 2016 · 1 comment
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Milestone

Comments

@kuboj
Copy link
Contributor

kuboj commented May 3, 2016

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
ansible 2.0.2.0

(tested also on current devel - c42501c with same result)

CONFIGURATION

default

OS / ENVIRONMENT

N/A

SUMMARY

Ansible fails when until condition is true on last retry.

STEPS TO REPRODUCE

site.yml


---
- name: test
  hosts: 127.0.0.1
  connection: local
  gather_facts: no
  tasks:
    - shell: bash foo.sh
      register: result
      retries: 2
      delay: 1
      until: result.rc == 0

    - debug: var=result

foo.sh
(this script basically returns exit code 1 on first run and 0 on second run)

#!/bin/bash

if [ -f /tmp/foo ]; then
  exit 0
else
  touch /tmp/foo
  exit 1
fi
EXPECTED RESULTS

Expected result would be to successfully execute playbook without any errors, because second exit code (rc) of execution of foo.sh is 0.

PLAY [test] ********************************************************************

TASK [command] *****************************************************************
FAILED - RETRYING: TASK: command (1 retries left).
changed: [127.0.0.1]

TASK [debug] *******************************************************************
ok: [127.0.0.1] => {
    "result": {
        "changed": true, 
        "cmd": "bash foo.sh", 
        "delta": "0:00:00.002049", 
        "end": "2016-05-03 12:27:47.893551", 
        "rc": 0, 
        "start": "2016-05-03 12:27:47.891502", 
        "stderr": "", 
        "stdout": "", 
        "stdout_lines": [], 
        "warnings": []
    }
}

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=2    changed=1    unreachable=0    failed=0 
ACTUAL RESULTS
Loaded callback default of type stdout, v2.0

PLAYBOOK: site.yml *************************************************************
1 plays in site.yml

PLAY [test] ********************************************************************

TASK [command] *****************************************************************
task path: /home/bubo/rsd/playground/ansible/site.yml:7
ESTABLISH LOCAL CONNECTION FOR USER: bubo
127.0.0.1 EXEC /bin/sh -c '( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1462271323.11-38155706394314 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1462271323.11-38155706394314 `" )'
127.0.0.1 PUT /tmp/tmpi2uVIH TO /home/bubo/.ansible/tmp/ansible-tmp-1462271323.11-38155706394314/command
127.0.0.1 EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/bubo/.ansible/tmp/ansible-tmp-1462271323.11-38155706394314/command; rm -rf "/home/bubo/.ansible/tmp/ansible-tmp-1462271323.11-38155706394314/" > /dev/null 2>&1'
FAILED - RETRYING: TASK: command (1 retries left).Result was: {"attempts": 1, "changed": true, "cmd": "bash foo.sh", "delta": "0:00:00.003411", "end": "2016-05-03 12:28:43.169459", "failed": true, "invocation": {"module_args": {"_raw_params": "bash foo.sh", "_uses_shell": true, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 1, "retries": 2, "start": "2016-05-03 12:28:43.166048", "stderr": "", "stdout": "", "stdout_lines": [], "warnings": []}
127.0.0.1 EXEC /bin/sh -c '( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1462271324.2-155682497181722 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1462271324.2-155682497181722 `" )'
127.0.0.1 PUT /tmp/tmpc0B7kH TO /home/bubo/.ansible/tmp/ansible-tmp-1462271324.2-155682497181722/command
127.0.0.1 EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/bubo/.ansible/tmp/ansible-tmp-1462271324.2-155682497181722/command; rm -rf "/home/bubo/.ansible/tmp/ansible-tmp-1462271324.2-155682497181722/" > /dev/null 2>&1'
fatal: [127.0.0.1]: FAILED! => {"attempts": 2, "changed": true, "cmd": "bash foo.sh", "delta": "0:00:00.003639", "end": "2016-05-03 12:28:44.245498", "failed": true, "invocation": {"module_args": {"_raw_params": "bash foo.sh", "_uses_shell": true, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 0, "start": "2016-05-03 12:28:44.241859", "stderr": "", "stdout": "", "stdout_lines": [], "warnings": []}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @site.retry

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=0    changed=0    unreachable=0    failed=1   
  • If retries is changed to >2 (e.g. 3), foo.sh is still executed only 2 times, but playbook execution is marked as successful.
  • If line failed_when: result.rc != 0 is added to the task, playbook execution works without any problems. (But one would expect that this "implicit" failed_when clause is not needed)
@abadger abadger added bug_report P2 Priority 2 - Issue Blocks Release labels May 4, 2016
@abadger abadger added this to the 2.1.0 milestone May 4, 2016
jimi-c added a commit that referenced this issue May 12, 2016
Prior to this patch, the retry/until logic would fail any task that
succeeded if it took all of the alloted retries to succeed. This patch
reworks the retry/until logic to make things more simple and clear.

Fixes #15697
jimi-c added a commit that referenced this issue May 13, 2016
Prior to this patch, the retry/until logic would fail any task that
succeeded if it took all of the alloted retries to succeed. This patch
reworks the retry/until logic to make things more simple and clear.

Fixes #15697
@jimi-c jimi-c closed this as completed in 4f0be29 May 13, 2016
@jimi-c
Copy link
Member

jimi-c commented May 13, 2016

Closing This Ticket

Hi!

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

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!

@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
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

No branches or pull requests

4 participants