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

fix: correct computation for range end has been added #975

Merged
merged 4 commits into from
Jun 29, 2021
Merged

fix: correct computation for range end has been added #975

merged 4 commits into from
Jun 29, 2021

Conversation

oukooveu
Copy link
Contributor

@oukooveu oukooveu commented Jun 28, 2021

Depends-On: #977

playbook:

---
- hosts: localhost
  vars:
    ansible_test_split_in: 3
    number_entries: 10
  tasks:
    - set_fact:  
        _iter_by: "{{ (number_entries|int / ansible_test_split_in)|round(0, 'ceil')|int }}"
    - set_fact:
        _start_at: "{{ (_iter_by|int * ansible_test_do_number|int) - _iter_by|int }}"
    - set_fact:
        _end_at: "{{ _start_at|int + _iter_by|int }}"
    - debug:
        msg: "iter: {{ _iter_by }}, start: {{ _start_at }}, end: {{ _end_at }}"

produces:

➭ for i in {1..3}; do ansible-playbook a.yaml -e ansible_test_do_number=$i 2>&1; done | grep iter
iter: 4, start: 0, end: 4
iter: 4, start: 4, end: 8
iter: 4, start: 8, end: 12

and with the fix:

➭ for i in {1..3}; do ansible-playbook a.yaml -e ansible_test_do_number=$i 2>&1; done | grep iter
iter: 4, start: 0, end: 3
iter: 4, start: 4, end: 7
iter: 4, start: 8, end: 9

@oukooveu oukooveu changed the title fix: correct computation for rage end has been added fix: correct computation for range end has been added Jun 28, 2021
goneri added a commit to goneri/community.aws that referenced this pull request Jun 28, 2021
Depends-On: ansible/ansible-zuul-jobs#975

First iteration, a lot of dup code. Do Not Merge
@goneri
Copy link
Collaborator

goneri commented Jun 28, 2021

The patch fails with:

2021-06-28 23:32:30.136162 | TASK [ansible-test : set_fact]
2021-06-28 23:32:30.237457 | centos-8 | ERROR
2021-06-28 23:32:30.237852 | centos-8 | {
2021-06-28 23:32:30.237933 | centos-8 |   "msg": "Unexpected templating type error occurred on ({{ _start_at|int + _iter_by|int - 1 if ansible_test_do_number|int != ansible_test_split_in else number_entries - 1 }}): unsupported operand type(s) for -: 'AnsibleUnsafeText' and 'int'"
2021-06-28 23:32:30.238005 | centos-8 | }

See: https://12fe1135c8196b12c4b6-e2f208063caf47ac7c7f910eb7b74d11.ssl.cf2.rackcdn.com/563/3fe49fb9bd81c4162e192fd024967fd0af6f6615/check/ansible-test-cloud-integration-aws-py36_3_of_3/cce8104/job-output.txt

@oukooveu
Copy link
Contributor Author

@goneri can't reproduce this, do you have any ideas what's wrong?

TASK [debug] **********************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "iter: 4, start: 8, end: 9"
}

PLAY RECAP ************************************************************************************************************************************************************************************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

(.venv) [root@fa8688e0936f ansible-zuul-jobs]# 
(.venv) [root@fa8688e0936f ansible-zuul-jobs]# cat /etc/redhat-release 
CentOS Linux release 8.4.2105
(.venv) [root@fa8688e0936f ansible-zuul-jobs]# ansible --version
ansible 2.9.13
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/.venv/lib64/python3.6/site-packages/ansible
  executable location = /root/.venv/bin/ansible
  python version = 3.6.8 (default, Mar 19 2021, 05:13:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
(.venv) [root@fa8688e0936f ansible-zuul-jobs]# 

@oukooveu
Copy link
Contributor Author

@goneri I've added an additional int filter and dependency in ansible-collections/community.aws#547 and mentioned issue went but tests were not started and there is issue for small amount of tests (when we have targets less than amount of workers). I've decided to return my suggestion from #968 -- in this case we don't need to operate with ranges, have more readable and understandable code, and this code works as expected (see ansible-collections/community.aws#547 as an example).

@goneri
Copy link
Collaborator

goneri commented Jun 29, 2021

I get the following err:

2021-06-29 14:48:40.312847 | TASK [ansible-test : set_fact]
2021-06-29 14:48:40.414634 | centos-8 | ERROR
2021-06-29 14:48:40.415047 | centos-8 | {
2021-06-29 14:48:40.415127 | centos-8 |   "msg": "The task includes an option with an undefined variable. The error was: '_hashed_targets' is undefined\n\nThe error appears to be in '/var/lib/zuul/builds/d7b84704b9a5443eb498f860bdd3ceef/untrusted/project_0/github.com/ansible/ansible-zuul-jobs/roles/ansible-test/tasks/split_targets.yaml': line 17, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  loop: '{{ ansible_test_targets.stdout_lines }}'\n- set_fact:\n  ^ here\n"
2021-06-29 14:48:40.415205 | centos-8 | }

@goneri
Copy link
Collaborator

goneri commented Jun 29, 2021

I'm testing with this extra patch: 6c848f2

@goneri
Copy link
Collaborator

goneri commented Jun 29, 2021

Ok, I think your patch is good, I just found two extra problems :-). #977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants