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

failed to use variable for retries in the loop #5865

Closed
jack1402 opened this issue Feb 3, 2014 · 10 comments · Fixed by #9772
Closed

failed to use variable for retries in the loop #5865

jack1402 opened this issue Feb 3, 2014 · 10 comments · Fixed by #9772
Labels
bug This issue/PR relates to a bug.

Comments

@jack1402
Copy link

jack1402 commented Feb 3, 2014

Issue Type:

“Bug Report”

Ansible Version:

1.4.3

Environment:

RHEL 6.5

Summary:

we are trying to use the variable for the value of retries at loop. But always hit an error

Steps To Reproduce:

Run following playbook:

hosts: localhost 
     vars: tries: 5 
tasks:
     - name: test
       debug: msg="looping" 
       register: output 
       until: no 
       retries: "{{ tries | int }}" 
       delay: 1
Expected Results:

retries count is 5

Actual Results:

get following error:

TASK: [test] ******************************************************************
fatal: [localhost] => Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/ansible/runner/init.py", line 394, in executor
execrc = self.executorinternal(host, new_stdin)
File "/usr/lib/python2.6/site-packages/ansible/runner/init.py", line 485, in executorinternal
return self.executorinternal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
File "/usr/lib/python2.6/site-packages/ansible/runner/init.py", line 694, in executorinternal_inner
for x in range(1, retries + 1):
TypeError: cannot concatenate 'str' and 'int' objects

FATAL: all hosts have already failed -- aborting

@mpdehaan mpdehaan added the P3 label Mar 19, 2014
@mpdehaan mpdehaan added P4 and removed P3 labels Apr 17, 2014
@rafecolton
Copy link

Looks like this is still an issue with 1.8.2?

rafecolton pushed a commit to modcloth/ansible-role-modcloth-app that referenced this issue Dec 10, 2014
jszwedko added a commit to jszwedko/ansible that referenced this issue Dec 10, 2014
@evgeny-goldin
Copy link

Yes, in 1.8.2

retries: '{{ 5 }}'

produces

  File "/usr/local/lib/python2.7/site-packages/ansible/runner/__init__.py", line 590, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/usr/local/lib/python2.7/site-packages/ansible/runner/__init__.py", line 818, in _executor_internal
    complex_args=complex_args
  File "/usr/local/lib/python2.7/site-packages/ansible/runner/__init__.py", line 1035, in _executor_internal_inner
    for x in range(1, int(retries) + 1):
ValueError: invalid literal for int() with base 10: '{{ 5 }}'

jimi-c pushed a commit that referenced this issue Feb 17, 2015
@srikanthsrs
Copy link

In which version is this fixed?

@evgeny-goldin
Copy link

I have it working with Ansible 1.8.4.

@semente
Copy link

semente commented Apr 22, 2017

Hey guys, looks like we have a regression on 2.3.0, at least when using on docker_service.scale:

    - name: set up web apps
      docker_service:
        project_src: "/srv/{{ item }}"
        stopped: "{{ instances.get(item).is_disabled | default('false') }}"
        pull: yes
        scale:
          web: "{{ instances.get(item).scale }}"
      with_items: "{{ web_instances }}"

I've tried with and without | int. Any advice? Is it really a regression? On 2.2.0 it used to work.

@kassiansun
Copy link
Contributor

@semente You can ignore the double quotes, like web: {{ instances.get(item).scale }}

@semente
Copy link

semente commented May 19, 2017

@kassiansun thanks but that won't work due a syntax error.

Always quote template expression brackets when they start a value

@kassiansun
Copy link
Contributor

@semente Oh, it can be used in jinja2 templates, but you're using this in playbooks.

I submitted a patch to my own repository: https://github.com/kassiansun/ansible/commit/59e38bd4bc383a608b62a6cc6b6c89d201203226, you can hot fix the code in /usr/lib/python2.7/site-packages/ansible/modules/cloud/docker/docker_service.py. If it works, I will submit a MR to this repository.

Many ansible modules are poorly maintained like docker_service

@semente
Copy link

semente commented May 30, 2017

Hey @kassiansun, awesome! I didn't work on this project since them but I will test your patch asap and I let you know if it fixed the issue. Thanks!!

By the way, should I open a new Issue or that won't be necessary?

@kassiansun
Copy link
Contributor

@semente Seems a good idea, as this issue is closed long time ago.

rafecolton pushed a commit to himalayan-institute/ansible-role-hi-app that referenced this issue Feb 9, 2018
Now that ansible/ansible#5865 has long-since
been fixed
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 24, 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants