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

Is it possible to have until with loop? #44741

Closed
nkakouros opened this issue Aug 27, 2018 · 5 comments
Closed

Is it possible to have until with loop? #44741

nkakouros opened this issue Aug 27, 2018 · 5 comments
Labels
affects_2.7 This issue/PR affects Ansible v2.7 docs This issue/PR relates to or includes documentation. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@nkakouros
Copy link
Contributor

SUMMARY

I have a get_url task that downloads a list of files. Sometimes the server is busy and a download might fail. I would like to use until to retry the download.

ISSUE TYPE
  • Documentation Report
COMPONENT NAME
ANSIBLE VERSION
ansible 2.7.0.dev0 (devel 79a020e312) last updated 2018/08/27 12:47:42 (GMT +200)
  config file = None
  configured module search path = ['/home/nikos/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/nikos/Projects/ansible/lib/ansible
  executable location = /home/nikos/Projects/ansible/bin/ansible
  python version = 3.7.0 (default, Jul 15 2018, 10:44:58) [GCC 8.1.1 20180531]
CONFIGURATION
OS / ENVIRONMENT

Arch linux

STEPS TO REPRODUCE

I would imagine sth like this:

- get_url:
    url: "{{ item }}"
    dest: 'dest'
  register: download
  until: download.results | map('success')
  loop: "{{ files }}"

But this obviously does not work.

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 docs This issue/PR relates to or includes documentation. 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 Aug 27, 2018
@webknjaz webknjaz removed the needs_triage Needs a first human triage before being processed. label Aug 28, 2018
@webknjaz

This comment has been minimized.

@webknjaz

This comment has been minimized.

@webknjaz
Copy link
Member

webknjaz commented Aug 28, 2018

So I've finally realized that you try to access a list of results, but until works with every separate task run. This works:

---
- hosts: localhost
  tasks:
  - get_url:
      url: https://github.com/file/file/archive/FILE5_34.tar.gz
      dest: .
    register: download
    until: download.results | map('success')
    delay: 3

Under each loop, the until is bound to the task within/inside that loop, not to the set of results after loop evaluation. This is what you're supposed to do:

---
- hosts: localhost
  tasks:
  - get_url:
      url: "{{ item }}"
      dest: .
    register: download
    until: download is succeeded
    delay: 3
    loop:
    - https://github.com/file/file/archive/FILE5_34.tar.gz
    - https://github.com/file/file/archive/FILE5_33.tar.gz

It'll retry each of downloads separately.

@webknjaz

This comment has been minimized.

@webknjaz
Copy link
Member

webknjaz commented Sep 4, 2018

So we have a discussion ansible/proposals#140 and #44927 which demos the current behavior.
This issue is more of a proposal, which belongs more to the proposals repo, so if you have something to add let's move our conversation to that proposal :)

@webknjaz webknjaz closed this as completed Sep 4, 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.7 This issue/PR affects Ansible v2.7 docs This issue/PR relates to or includes documentation. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

3 participants