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

Do Until "attempts" key is missing #17258

Closed
nneil opened this issue Aug 26, 2016 · 3 comments
Closed

Do Until "attempts" key is missing #17258

nneil opened this issue Aug 26, 2016 · 3 comments
Assignees
Labels
affects_2.1 This issue/PR affects Ansible v2.1 affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Milestone

Comments

@nneil
Copy link

nneil commented Aug 26, 2016

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Loops

ANSIBLE VERSION
ansible 2.1.1.0
  config file = /home/nneil/playbooks/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION
OS / ENVIRONMENT
SUMMARY

Do Until documentation says:

The task returns the results returned by the last task run. The results of individual retries can be viewed by -vv option. The registered variable will also have a new key “attempts” which will have the number of the retries for the task.

But the attempts key is missing

STEPS TO REPRODUCE

$ more ansible-bug.play
- hosts: all
  tasks:
  - lineinfile: dest="/tmp/demo" regexp="^([^#].*)" line="#\1" backrefs=yes
    register: result
    until: not result.changed
    retries: 9999
    #changed_when: result.attempts>0
  - debug: var=result
ansible-playbook -i localhost.inventory ansible-bug.play

PLAY [all] *********************************************************************

TASK [setup gather_subset=all] *************************************************
ok: [localhost]

TASK [lineinfile dest=/tmp/demo, regexp=^([^#].*), line=#\1, backrefs=yes] *****
FAILED - RETRYING: TASK: lineinfile (9999 retries left).
FAILED - RETRYING: TASK: lineinfile (9998 retries left).
FAILED - RETRYING: TASK: lineinfile (9997 retries left).
FAILED - RETRYING: TASK: lineinfile (9996 retries left).
FAILED - RETRYING: TASK: lineinfile (9995 retries left).
ok: [localhost]

TASK [debug var=result] ********************************************************
ok: [localhost] => {
    "result": {
        "backup": "",
        "changed": false,
        "diff": [
            {
                "after": "",
                "after_header": "/tmp/demo (content)",
                "before": "",
                "before_header": "/tmp/demo (content)"
            },
            {
                "after_header": "/tmp/demo (file attributes)",
                "before_header": "/tmp/demo (file attributes)"
            }
        ],
        "msg": ""
    }
}

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0


@jctanner jctanner added bug_report P2 Priority 2 - Issue Blocks Release labels Aug 26, 2016
@gstaicu
Copy link
Contributor

gstaicu commented Aug 30, 2016

The reported problem come from line 261 in /usr/lib/python2.7/dist-packages/ansible/plugins/callback/default.py.

If you change this line to: msg = "FAILED - RETRYING: %s (%d retries left, %d attempts done)." % (result._task, result._result['retries'] - result._result['attempts'], result._result['attempts'])

The output will be like:

PLAYBOOK: ansible-bug.play *****************************************************
1 plays in ansible-bug.play

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [lineinfile] **************************************************************
task path: /home/gabrielstaicu/contrib_ansible/ansible-bug.play:3
FAILED - RETRYING: TASK: lineinfile (9999 retries left, 1 attempts done).
FAILED - RETRYING: TASK: lineinfile (9998 retries left, 2 attempts done).
FAILED - RETRYING: TASK: lineinfile (9997 retries left, 3 attempts done).
FAILED - RETRYING: TASK: lineinfile (9996 retries left, 4 attempts done).
FAILED - RETRYING: TASK: lineinfile (9995 retries left, 5 attempts done).
FAILED - RETRYING: TASK: lineinfile (9994 retries left, 6 attempts done).
FAILED - RETRYING: TASK: lineinfile (9993 retries left, 7 attempts done).
FAILED - RETRYING: TASK: lineinfile (9992 retries left, 8 attempts done).
ok: [localhost] => {"backup": "", "changed": false, "msg": ""}

TASK [debug] *******************************************************************
task path: /home/gabrielstaicu/contrib_ansible/ansible-bug.play:8
ok: [localhost] => {
"result": {
"backup": "",
"changed": false,
"diff": [
{
"after": "",
"after_header": "/tmp/demo (content)",
"before": "",
"before_header": "/tmp/demo (content)"
},
{
"after_header": "/tmp/demo (file attributes)",
"before_header": "/tmp/demo (file attributes)"
}
],
"msg": ""
}
}

PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0

@ansibot ansibot added triage affects_2.1 This issue/PR affects Ansible v2.1 labels Sep 7, 2016
@bcoca bcoca removed the triage label Sep 10, 2016
@jimi-c
Copy link
Member

jimi-c commented Sep 23, 2016

In testing this on the most recent devel/stable-2.1, I actually see quite a different result:

[jamesc@jimi testing]$ ansible-playbook -vvv 17258.yml 
Using /etc/ansible/ansible.cfg as config file
PLAYBOOK: 17258.yml ************************************************************
1 plays in 17258.yml
PLAY [localhost] ***************************************************************
TASK [lineinfile] **************************************************************
task path: /home/jamesc/testing/17258.yml:4
Using module file /data/devel/ansible/lib/ansible/modules/core/files/lineinfile.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: jamesc
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python && sleep 0'
fatal: [localhost]: FAILED! => {
    "failed": true, 
    "msg": "The conditional check 'not result.changed' failed. The error was: error while evaluating conditional (not result.changed): 'dict object' has no attribute 'changed'"
}
PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1   

@jimi-c jimi-c added the affects_2.2 This issue/PR affects Ansible v2.2 label Sep 23, 2016
@jimi-c jimi-c self-assigned this Sep 23, 2016
@jimi-c jimi-c modified the milestone: 2.2.0 Sep 23, 2016
@jimi-c jimi-c closed this as completed in 657506c Oct 2, 2016
@jimi-c
Copy link
Member

jimi-c commented Oct 2, 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!

sereinity pushed a commit to sereinity-forks/ansible that referenced this issue Jan 25, 2017
@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
affects_2.1 This issue/PR affects Ansible v2.1 affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

No branches or pull requests

6 participants